diff --git a/src/bot.ts b/src/bot.ts index 8550303..a18e344 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -69,8 +69,8 @@ export default class { return; } - if (command.executeFromInteraction) { - await command.executeFromInteraction(interaction); + if (command.execute) { + await command.execute(interaction); } } catch (error: unknown) { debug(error); diff --git a/src/commands/clear.ts b/src/commands/clear.ts index 5c1a1eb..2b258cb 100644 --- a/src/commands/clear.ts +++ b/src/commands/clear.ts @@ -19,7 +19,7 @@ export default class implements Command { this.playerManager = playerManager; } - public async executeFromInteraction(interaction: CommandInteraction) { + public async execute(interaction: CommandInteraction) { this.playerManager.get(interaction.guild!.id).clear(); await interaction.reply('clearer than a field after a fresh harvest'); diff --git a/src/commands/disconnect.ts b/src/commands/disconnect.ts index d196985..c63f9a2 100644 --- a/src/commands/disconnect.ts +++ b/src/commands/disconnect.ts @@ -20,7 +20,7 @@ export default class implements Command { this.playerManager = playerManager; } - public async executeFromInteraction(interaction: CommandInteraction) { + public async execute(interaction: CommandInteraction) { const player = this.playerManager.get(interaction.guild!.id); if (!player.voiceConnection) { diff --git a/src/commands/fseek.ts b/src/commands/fseek.ts index 5a46a17..f4f1172 100644 --- a/src/commands/fseek.ts +++ b/src/commands/fseek.ts @@ -25,7 +25,7 @@ export default class implements Command { this.playerManager = playerManager; } - public async executeFromInteraction(interaction: CommandInteraction): Promise { + public async execute(interaction: CommandInteraction): Promise { const player = this.playerManager.get(interaction.guild!.id); const currentSong = player.getCurrent(); diff --git a/src/commands/index.ts b/src/commands/index.ts index 1cd927b..b9f5877 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -1,14 +1,10 @@ import {SlashCommandBuilder} from '@discordjs/builders'; import {ButtonInteraction, CommandInteraction} from 'discord.js'; -export default class Command { - // TODO: remove - name?: string; - aliases?: string[]; - examples?: string[][]; - readonly slashCommand?: Partial & Pick; +export default interface Command { + readonly slashCommand: Partial & Pick; readonly handledButtonIds?: readonly string[]; readonly requiresVC?: boolean; - executeFromInteraction?: (interaction: CommandInteraction) => Promise; + execute: (interaction: CommandInteraction) => Promise; handleButtonInteraction?: (interaction: ButtonInteraction) => Promise; } diff --git a/src/commands/pause.ts b/src/commands/pause.ts index c3e8c24..5d87b87 100644 --- a/src/commands/pause.ts +++ b/src/commands/pause.ts @@ -21,7 +21,7 @@ export default class implements Command { this.playerManager = playerManager; } - public async executeFromInteraction(interaction: CommandInteraction) { + public async execute(interaction: CommandInteraction) { const player = this.playerManager.get(interaction.guild!.id); if (player.status !== STATUS.PLAYING) { diff --git a/src/commands/play.ts b/src/commands/play.ts index 4ac566b..619c18f 100644 --- a/src/commands/play.ts +++ b/src/commands/play.ts @@ -40,7 +40,7 @@ export default class implements Command { } // eslint-disable-next-line complexity - public async executeFromInteraction(interaction: CommandInteraction): Promise { + public async execute(interaction: CommandInteraction): Promise { const [targetVoiceChannel] = getMemberVoiceChannel(interaction.member as GuildMember) ?? getMostPopularVoiceChannel(interaction.guild!); const settings = await prisma.setting.findUnique({where: {guildId: interaction.guild!.id}}); diff --git a/src/commands/queue.ts b/src/commands/queue.ts index 479bc33..9768f58 100644 --- a/src/commands/queue.ts +++ b/src/commands/queue.ts @@ -23,7 +23,7 @@ export default class implements Command { this.updatingQueueEmbedManager = updatingQueueEmbedManager; } - public async executeFromInteraction(interaction: CommandInteraction) { + public async execute(interaction: CommandInteraction) { const embed = this.updatingQueueEmbedManager.get(interaction.guild!.id); await embed.createFromInteraction(interaction); diff --git a/src/commands/remove.ts b/src/commands/remove.ts index 76ba901..c58fbdf 100644 --- a/src/commands/remove.ts +++ b/src/commands/remove.ts @@ -27,7 +27,7 @@ export default class implements Command { this.playerManager = playerManager; } - public async executeFromInteraction(interaction: CommandInteraction): Promise { + public async execute(interaction: CommandInteraction): Promise { const player = this.playerManager.get(interaction.guild!.id); const position = interaction.options.getInteger('position') ?? 1; diff --git a/src/commands/seek.ts b/src/commands/seek.ts index 708567f..ecfde64 100644 --- a/src/commands/seek.ts +++ b/src/commands/seek.ts @@ -26,7 +26,7 @@ export default class implements Command { this.playerManager = playerManager; } - public async executeFromInteraction(interaction: CommandInteraction): Promise { + public async execute(interaction: CommandInteraction): Promise { const player = this.playerManager.get(interaction.guild!.id); const currentSong = player.getCurrent(); diff --git a/src/commands/shortcuts.ts b/src/commands/shortcuts.ts deleted file mode 100644 index e40d10a..0000000 --- a/src/commands/shortcuts.ts +++ /dev/null @@ -1,128 +0,0 @@ -import {Message} from 'discord.js'; -import {injectable} from 'inversify'; -import errorMsg from '../utils/error-msg.js'; -import Command from '.'; -import {prisma} from '../utils/db.js'; - -@injectable() -export default class implements Command { - public name = 'shortcuts'; - public aliases = []; - public examples = [ - ['shortcuts', 'show all shortcuts'], - ['shortcuts set s skip', 'aliases `s` to `skip`'], - ['shortcuts set party play https://www.youtube.com/watch?v=zK6oOJ1wz8k', 'aliases `party` to a specific play command'], - ['shortcuts delete party', 'removes the `party` shortcut'], - ]; - - public async execute(msg: Message, args: string []): Promise { - if (args.length === 0) { - // Get shortcuts for guild - const shortcuts = await prisma.shortcut.findMany({ - where: { - guildId: msg.guild!.id, - }, - }); - - if (shortcuts.length === 0) { - await msg.channel.send('no shortcuts exist'); - return; - } - - // Get prefix for guild - const settings = await prisma.setting.findUnique({ - where: { - guildId: msg.guild!.id, - }, - }); - - if (!settings) { - return; - } - - const {prefix} = settings; - - const res = shortcuts.reduce((accum, shortcut) => { - accum += `${prefix}${shortcut.shortcut}: ${shortcut.command}\n`; - - return accum; - }, ''); - - await msg.channel.send(res); - } else { - const action = args[0]; - - const shortcutName = args[1]; - - switch (action) { - case 'set': { - const shortcut = await prisma.shortcut.findFirst({ - where: { - guildId: msg.guild!.id, - shortcut: shortcutName, - }, - }); - - const command = args.slice(2).join(' '); - - const newShortcut = {shortcut: shortcutName, command, guildId: msg.guild!.id, authorId: msg.author.id}; - - if (shortcut) { - if (shortcut.authorId !== msg.author.id && msg.author.id !== msg.guild!.ownerId) { - await msg.channel.send(errorMsg('you do\'nt have permission to do that')); - return; - } - - await prisma.shortcut.update({ - where: { - id: shortcut.id, - }, - data: newShortcut, - }); - await msg.channel.send('shortcut updated'); - } else { - await prisma.shortcut.create({data: newShortcut}); - await msg.channel.send('shortcut created'); - } - - break; - } - - case 'delete': { - // Check if shortcut exists - const shortcut = await prisma.shortcut.findFirst({ - where: { - guildId: msg.guild!.id, - shortcut: shortcutName, - }, - }); - - if (!shortcut) { - await msg.channel.send(errorMsg('shortcut doesn\'t exist')); - return; - } - - // Check permissions - if (shortcut.authorId !== msg.author.id && msg.author.id !== msg.guild!.ownerId) { - await msg.channel.send(errorMsg('you don\'t have permission to do that')); - return; - } - - await prisma.shortcut.delete({ - where: { - id: shortcut.id, - }, - }); - - await msg.channel.send('shortcut deleted'); - - break; - } - - default: { - await msg.channel.send(errorMsg('unknown command')); - } - } - } - } -} diff --git a/src/commands/shuffle.ts b/src/commands/shuffle.ts index f560e41..9c0a664 100644 --- a/src/commands/shuffle.ts +++ b/src/commands/shuffle.ts @@ -20,7 +20,7 @@ export default class implements Command { this.playerManager = playerManager; } - public async executeFromInteraction(interaction: CommandInteraction): Promise { + public async execute(interaction: CommandInteraction): Promise { const player = this.playerManager.get(interaction.guild!.id); if (player.isQueueEmpty()) { diff --git a/src/commands/skip.ts b/src/commands/skip.ts index 93b8bc3..f8900da 100644 --- a/src/commands/skip.ts +++ b/src/commands/skip.ts @@ -1,9 +1,8 @@ -import {CommandInteraction, Message, TextChannel} from 'discord.js'; +import {CommandInteraction} from 'discord.js'; import {TYPES} from '../types.js'; import {inject, injectable} from 'inversify'; import PlayerManager from '../managers/player.js'; import Command from '.'; -import LoadingMessage from '../utils/loading-message.js'; import errorMsg from '../utils/error-msg.js'; import {SlashCommandBuilder} from '@discordjs/builders'; @@ -32,7 +31,7 @@ export default class implements Command { this.playerManager = playerManager; } - public async executeFromInteraction(interaction: CommandInteraction): Promise { + public async execute(interaction: CommandInteraction): Promise { const numToSkip = interaction.options.getInteger('skip') ?? 1; if (numToSkip < 1) { @@ -48,27 +47,4 @@ export default class implements Command { await interaction.reply({content: errorMsg('invalid number of songs to skip'), ephemeral: true}); } } - - public async execute(msg: Message, args: string []): Promise { - let numToSkip = 1; - - if (args.length === 1) { - if (!Number.isNaN(parseInt(args[0], 10))) { - numToSkip = parseInt(args[0], 10); - } - } - - const player = this.playerManager.get(msg.guild!.id); - - const loader = new LoadingMessage(msg.channel as TextChannel); - - try { - await loader.start(); - await player.forward(numToSkip); - - await loader.stop('keep \'er movin\''); - } catch (_: unknown) { - await loader.stop(errorMsg('no song to skip to')); - } - } } diff --git a/src/commands/unskip.ts b/src/commands/unskip.ts index 6842498..746cdf9 100644 --- a/src/commands/unskip.ts +++ b/src/commands/unskip.ts @@ -20,7 +20,7 @@ export default class implements Command { this.playerManager = playerManager; } - public async executeFromInteraction(interaction: CommandInteraction): Promise { + public async execute(interaction: CommandInteraction): Promise { const player = this.playerManager.get(interaction.guild!.id); try { diff --git a/src/inversify.config.ts b/src/inversify.config.ts index 623e631..5714d6f 100644 --- a/src/inversify.config.ts +++ b/src/inversify.config.ts @@ -23,7 +23,6 @@ import Play from './commands/play.js'; import QueueCommand from './commands/queue.js'; import Remove from './commands/remove.js'; import Seek from './commands/seek.js'; -import Shortcuts from './commands/shortcuts.js'; import Shuffle from './commands/shuffle.js'; import Skip from './commands/skip.js'; import Unskip from './commands/unskip.js'; @@ -63,7 +62,6 @@ container.bind(TYPES.Services.NaturalLanguage).to(NaturalLangua QueueCommand, Remove, Seek, - Shortcuts, Shuffle, Skip, Unskip,