Skip to content

Commit

Permalink
Fix voice joining and other commands
Browse files Browse the repository at this point in the history
  • Loading branch information
keybraker committed Nov 5, 2024
1 parent b5c6007 commit ac2099a
Show file tree
Hide file tree
Showing 17 changed files with 241 additions and 202 deletions.
31 changes: 29 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"eslint-config-prettier": "9.1.0",
"ffmpeg-static": "5.2.0",
"jsonfile": "6.1.0",
"libsodium-wrappers": "^0.7.15",
"lodash": "4.17.21",
"mongoose": "8.8.0",
"optionator": "0.9.4",
Expand Down
3 changes: 2 additions & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import { Routes } from 'discord-api-types/v9';
import { Client } from 'discord.js';
import dotenv from 'dotenv';
import { transports } from 'winston';

import * as auth from './commands/auth';
import * as noAuth from './commands/noAuth';
import { clientHandler, connectToDiscord } from './handlers/discord.handler';
import { eventHandler } from './handlers/event.handler';
import { mongoHandler } from './handlers/mongo.handler';
import logger from './utilities/log.utility';
import { ActiveCooldowns } from './types/classes/PTypes.interface';
import logger from './utilities/log.utility';

dotenv.config();

Expand Down
4 changes: 1 addition & 3 deletions src/blueprints/attribute.blueprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async function updateVoiceChannelAttribute(pGuildId: PGuild['id'], pChannelId: P
return getResponse(response, category, attribute, value);
}

async function updateGuildAttribute(pGuildId: PGuild['id'], category: string[], attribute: string, value: string | number) {
async function updateGuildAttribute(pGuildId: PGuild['id'], category: string[], attribute: keyof PGuild, value: string | number) {
const response = await updateGuild(pGuildId, attribute, value);

return getResponse(response, category, attribute, value);
Expand All @@ -53,8 +53,6 @@ async function updateMemberAttribute(pGuildId: PGuild['id'], pMemberId: PMember[
return getResponse(response, category, attribute, value);
}

//

export const AttributeBlueprints: Blueprint[] = [
{
name: 'p.annAnnounce',
Expand Down
4 changes: 2 additions & 2 deletions src/commands/auth/delete_messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export = {
};
}

const result = askForApproval(
const result = await askForApproval(
interaction,
`*${interaction.user}, are you sure you want to delete **${bulkDeleteLength}** messages*?`,
ButtonStyle.Success
Expand All @@ -59,7 +59,7 @@ export = {
};
}

const messages = await (<TextChannel>interaction.channel).bulkDelete(bulkDeleteLength);
const messages = await (<TextChannel>interaction.channel).bulkDelete(bulkDeleteLength + 1);

if (!messages) {
return {
Expand Down
10 changes: 5 additions & 5 deletions src/commands/auth/invite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,27 @@ export = {
option
.setName('temporary')
.setDescription('should invite be temporary')
.setRequired(true))
.setRequired(false))
.addNumberOption(option =>
option
.setName('max_age')
.setDescription('what the maximum age of the invitee shall be')
.setRequired(true))
.setRequired(false))
.addNumberOption(option =>
option
.setName('max_uses')
.setDescription('maximum usages')
.setRequired(true))
.setRequired(false))
.addBooleanOption(option =>
option
.setName('unique')
.setDescription('should invite be unique')
.setRequired(true))
.setRequired(false))
.addStringOption(option =>
option
.setName('reason')
.setDescription('the reason for the invite')
.setRequired(true))
.setRequired(false))
.setContexts(InteractionContextType.Guild),
async execute(interaction: ChatInputCommandInteraction): Promise<ReturnPromise> {
const member = interaction.member as GuildMember;
Expand Down
141 changes: 47 additions & 94 deletions src/commands/auth/url.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { SlashCommandBuilder } from '@discordjs/builders';
import { ChatInputCommandInteraction, InteractionContextType, NewsChannel } from 'discord.js';

import { doesChannelHaveUsage } from '../../libraries/guild.library';
import { messageHelp } from '../../libraries/help.library';
import { insertURL } from '../../libraries/mongo.library';
import { Command } from '../../types/Command';
import { PGuild } from '../../types/classes/PGuild.class';
import { ReturnPromise, ScopeLimit } from '../../types/classes/PTypes.interface';

const COMMAND_NAME = 'url';
Expand All @@ -13,105 +19,52 @@ export = {
scopeLimit: ScopeLimit.NONE,
slashCommand: new SlashCommandBuilder()
.setName(COMMAND_NAME)
.setDescription(DESCRIPTION),
async execute(/* interaction: ChatInputCommandInteraction, pGuild: PGuild */): Promise<ReturnPromise> {
return {
result: false,
value: 'not yet implemented',
};
.setDescription(DESCRIPTION)
.addChannelOption((option) =>
option
.setName('url_channel')
.setDescription('the channel you want to make the url channel')
.setRequired(true))
.setContexts(InteractionContextType.Guild),
async execute(interaction: ChatInputCommandInteraction, pGuild: PGuild): Promise<ReturnPromise> {
const urlChannel = interaction.options.getChannel('url_channel');

// if (!interaction.guild) {
// return {
// result: false,
// value: 'guild could not be fetched',
// };
// }
if (!urlChannel) {
return {
result: false,
value: messageHelp('commands', 'url'),
};
}

// if (!interaction.channel) {
// return {
// result: false,
// value: 'channel could not be fetched',
// };
// }
if (!(urlChannel instanceof NewsChannel)) {
return {
result: false,
value: messageHelp('commands', 'url', 'channel must be news channel'),
};
}

// if (args.length === 0) {
// if (isUrlOnlyChannel(interaction.channel.id, pGuild)) {
// removeURL(pGuild.id, interaction.channel.id)
// .then((r: boolean) => {
// return {
// result: r,
// value: r ? 'successfully removed url channel' : 'failed to remove url channel',
// };
// })
// .catch((e: string) => {
// return {
// result: false,
// value: `failed to remove url channel: ${e}`,
// };
// });
// } else if (isAnnouncementChannel(interaction.channel.id, pGuild)) {
// return {
// result: false,
// value: "this can't be set as a URL channel for it is the Announcement channel",
// };
// } else if (isMusicChannel(interaction.channel.id, pGuild)) {
// return {
// result: true,
// value: "this can't be set as a URL channel for it is the Music channel",
// };
// } else {
// insertURL(pGuild.id, interaction.channel.id)
// .then((r) => {
// return {
// result: r,
// value: r ? 'set as an url channel successfully' : 'failed to set as an url channel',
// };
// })
// .catch((e) => {
// return {
// result: false,
// value: `failed to set as an url channel: ${e}`,
// };
// });
// }
// } else if (args.length > 0) {
// let urlChannel: string = args.join(' ').substring(0, args.join(' ').indexOf('|') - 1);
// let urlCategory: string | null = args.join(' ').substring(args.join(' ').indexOf('|'));
if (!urlChannel.isTextBased()) {
return {
result: false,
value: messageHelp('commands', 'url', 'channel must be text channel'),
};
}

// if (urlChannel === '' && urlCategory !== '') {
// urlChannel = urlCategory;
// urlCategory = null;
// }
const channelHasUsage = await doesChannelHaveUsage(urlChannel.id, pGuild);
if (channelHasUsage.result) {
return {
result: false,
value: channelHasUsage.value,
};
}

// const urlOptions = getOptions(interaction.guild, 'url only channel');
const response = await insertURL(pGuild.id, urlChannel.id);

// createChannel(interaction.guild, urlChannel, urlOptions, urlCategory)
// .then((rCreate) => {
// insertURL(pGuild.id, rCreate)
// .then((rUrl) => {
// return {
// result: rUrl,
// value: rUrl ? 'created url channel and category successfully' : 'failed to create a url channel',
// };
// })
// .catch((e) => {
// return {
// result: false,
// value: `failed to create a url channel: ${e}`,
// };
// });
// })
// .catch((e) => {
// return {
// result: false,
// value: `failed to create a url channel: ${e}`,
// };
// });
// }

// return {
// result: false,
// value: messageHelp('commands', 'url'),
// };
return {
result: response,
value: response
? 'new url channel set successfully'
: 'failed to set new url channel',
};
},
} as Command;
24 changes: 19 additions & 5 deletions src/commands/noAuth/join.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { SlashCommandBuilder } from '@discordjs/builders';
import { ChatInputCommandInteraction, Client } from 'discord.js';
import { ChatInputCommandInteraction } from 'discord.js';
import logger from '../../utilities/log.utility';

import { joinUserVoiceChannelByInteraction, messageHelp } from '../../libraries/help.library';
import { clientTalk } from '../../libraries/localisation.library';
import { Command } from '../../types/Command';
import { PGuild } from '../../types/classes/PGuild.class';
import { ReturnPromise, ScopeLimit } from '../../types/classes/PTypes.interface';
import { AnnouncementAction, ReturnPromise, ScopeLimit } from '../../types/classes/PTypes.interface';

const COMMAND_NAME = 'join';
const DESCRIPTION = 'makes portal join your voice channel'
Expand All @@ -17,18 +20,29 @@ export = {
slashCommand: new SlashCommandBuilder()
.setName(COMMAND_NAME)
.setDescription(DESCRIPTION),
async execute(interaction: ChatInputCommandInteraction, pGuild: PGuild, client: Client): Promise<ReturnPromise> {
async execute(interaction: ChatInputCommandInteraction, pGuild: PGuild): Promise<ReturnPromise> {
try {
await joinUserVoiceChannelByInteraction(client, interaction, pGuild /*, true*/);
const voiceChannel = await joinUserVoiceChannelByInteraction(interaction, pGuild);

if(!voiceChannel) {
return {
result: false,
value: 'failed to join voice channel',
};
}

clientTalk(interaction, pGuild, AnnouncementAction.join);

return {
result: true,
value: 'successfully joined voice channel',
};
}catch (error) {
logger.error(`commands.join.error: ${error}`);

return {
result: false,
value: messageHelp('commands', 'join', String(error)),
value: messageHelp('commands', 'join', 'failed to join voice channel'),
};
}
},
Expand Down
Loading

0 comments on commit ac2099a

Please sign in to comment.