From e7a87c4f529b85cf03a8a8cfc009336fd85334c9 Mon Sep 17 00:00:00 2001 From: Federico fuji97 Rapetti Date: Mon, 27 Dec 2021 16:56:19 +0100 Subject: [PATCH] Remove old functions from commands --- src/commands/remove.ts | 67 ++++++------------------------------------ src/commands/skip.ts | 3 +- src/commands/unskip.ts | 20 +------------ 3 files changed, 11 insertions(+), 79 deletions(-) diff --git a/src/commands/remove.ts b/src/commands/remove.ts index f0c1b15..76ba901 100644 --- a/src/commands/remove.ts +++ b/src/commands/remove.ts @@ -1,4 +1,4 @@ -import {CommandInteraction, Message} from 'discord.js'; +import {CommandInteraction} from 'discord.js'; import {inject, injectable} from 'inversify'; import {TYPES} from '../types.js'; import PlayerManager from '../managers/player.js'; @@ -10,7 +10,6 @@ import {SlashCommandBuilder} from '@discordjs/builders'; export default class implements Command { public readonly slashCommand = new SlashCommandBuilder() .setName('remove') - // TODO: make sure verb tense is consistent between all command descriptions .setDescription('remove songs from the queue') .addIntegerOption(option => option.setName('position') @@ -35,69 +34,21 @@ export default class implements Command { const range = interaction.options.getInteger('range') ?? 1; if (position < 1) { - await interaction.reply('position must be greater than 0'); + await interaction.reply({ + content: errorMsg('position must be greater than 0'), + ephemeral: true, + }); } if (range < 1) { - await interaction.reply('range must be greater than 0'); + await interaction.reply({ + content: errorMsg('range must be greater than 0'), + ephemeral: true, + }); } player.removeFromQueue(position, range); await interaction.reply(':wastebasket: removed'); } - - public async execute(msg: Message, args: string []): Promise { - const player = this.playerManager.get(msg.guild!.id); - - if (args.length === 0) { - await msg.channel.send(errorMsg('missing song position or range')); - return; - } - - const reg = /^(\d+)-(\d+)$|^(\d+)$/g; // Expression has 3 groups: x-y or z. x-y is range, z is a single digit. - const match = reg.exec(args[0]); - - if (match === null) { - await msg.channel.send(errorMsg('incorrect format')); - return; - } - - if (match[3] === undefined) { // 3rd group (z) doesn't exist -> a range - const range = [parseInt(match[1], 10), parseInt(match[2], 10)]; - - if (range[0] < 1) { - await msg.channel.send(errorMsg('position must be greater than 0')); - return; - } - - if (range[1] > player.queueSize()) { - await msg.channel.send(errorMsg('position is outside of the queue\'s range')); - return; - } - - if (range[0] < range[1]) { - player.removeFromQueue(range[0], range[1] - range[0] + 1); - } else { - await msg.channel.send(errorMsg('range is backwards')); - return; - } - } else { // 3rd group exists -> just one song - const index = parseInt(match[3], 10); - - if (index < 1) { - await msg.channel.send(errorMsg('position must be greater than 0')); - return; - } - - if (index > player.queueSize()) { - await msg.channel.send(errorMsg('position is outside of the queue\'s range')); - return; - } - - player.removeFromQueue(index, 1); - } - - await msg.channel.send(':wastebasket: removed'); - } } diff --git a/src/commands/skip.ts b/src/commands/skip.ts index e38204c..93b8bc3 100644 --- a/src/commands/skip.ts +++ b/src/commands/skip.ts @@ -18,8 +18,7 @@ export default class implements Command { public readonly slashCommand = new SlashCommandBuilder() .setName('skip') - // TODO: make sure verb tense is consistent between all command descriptions - .setDescription('skips the next songs') + .setDescription('skips the next songs') .addIntegerOption(option => option .setName('number') .setDescription('number of songs to skip [default: 1]') diff --git a/src/commands/unskip.ts b/src/commands/unskip.ts index 8945553..6842498 100644 --- a/src/commands/unskip.ts +++ b/src/commands/unskip.ts @@ -1,4 +1,4 @@ -import {CommandInteraction, Message} from 'discord.js'; +import {CommandInteraction} from 'discord.js'; import {TYPES} from '../types.js'; import {inject, injectable} from 'inversify'; import PlayerManager from '../managers/player.js'; @@ -12,12 +12,6 @@ export default class implements Command { .setName('unskip') .setDescription('goes back in the queue by one song'); - public name = 'unskip'; - public aliases = ['back']; - public examples = [ - ['unskip', 'goes back in the queue by one song'], - ]; - public requiresVC = true; private readonly playerManager: PlayerManager; @@ -40,16 +34,4 @@ export default class implements Command { }); } } - - public async execute(msg: Message, _: string []): Promise { - const player = this.playerManager.get(msg.guild!.id); - - try { - await player.back(); - - await msg.channel.send('back \'er up\''); - } catch (_: unknown) { - await msg.channel.send(errorMsg('no song to go back to')); - } - } }