Remove old functions from commands

This commit is contained in:
Federico fuji97 Rapetti 2021-12-27 16:56:19 +01:00
parent 29c32ce65e
commit e7a87c4f52
3 changed files with 11 additions and 79 deletions

View file

@ -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<void> {
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');
}
}

View file

@ -18,7 +18,6 @@ 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')
.addIntegerOption(option => option
.setName('number')

View file

@ -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<void> {
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'));
}
}
}