Type fixes, remove shortcuts

This commit is contained in:
Max Isom 2022-01-19 13:46:32 -06:00
parent ed4e7b5ceb
commit 4169104c4d
No known key found for this signature in database
GPG key ID: 25C9B1A7F6798880
15 changed files with 17 additions and 175 deletions

View file

@ -69,8 +69,8 @@ export default class {
return; return;
} }
if (command.executeFromInteraction) { if (command.execute) {
await command.executeFromInteraction(interaction); await command.execute(interaction);
} }
} catch (error: unknown) { } catch (error: unknown) {
debug(error); debug(error);

View file

@ -19,7 +19,7 @@ export default class implements Command {
this.playerManager = playerManager; this.playerManager = playerManager;
} }
public async executeFromInteraction(interaction: CommandInteraction) { public async execute(interaction: CommandInteraction) {
this.playerManager.get(interaction.guild!.id).clear(); this.playerManager.get(interaction.guild!.id).clear();
await interaction.reply('clearer than a field after a fresh harvest'); await interaction.reply('clearer than a field after a fresh harvest');

View file

@ -20,7 +20,7 @@ export default class implements Command {
this.playerManager = playerManager; this.playerManager = playerManager;
} }
public async executeFromInteraction(interaction: CommandInteraction) { public async execute(interaction: CommandInteraction) {
const player = this.playerManager.get(interaction.guild!.id); const player = this.playerManager.get(interaction.guild!.id);
if (!player.voiceConnection) { if (!player.voiceConnection) {

View file

@ -25,7 +25,7 @@ export default class implements Command {
this.playerManager = playerManager; this.playerManager = playerManager;
} }
public async executeFromInteraction(interaction: CommandInteraction): Promise<void> { public async execute(interaction: CommandInteraction): Promise<void> {
const player = this.playerManager.get(interaction.guild!.id); const player = this.playerManager.get(interaction.guild!.id);
const currentSong = player.getCurrent(); const currentSong = player.getCurrent();

View file

@ -1,14 +1,10 @@
import {SlashCommandBuilder} from '@discordjs/builders'; import {SlashCommandBuilder} from '@discordjs/builders';
import {ButtonInteraction, CommandInteraction} from 'discord.js'; import {ButtonInteraction, CommandInteraction} from 'discord.js';
export default class Command { export default interface Command {
// TODO: remove readonly slashCommand: Partial<SlashCommandBuilder> & Pick<SlashCommandBuilder, 'toJSON'>;
name?: string;
aliases?: string[];
examples?: string[][];
readonly slashCommand?: Partial<SlashCommandBuilder> & Pick<SlashCommandBuilder, 'toJSON'>;
readonly handledButtonIds?: readonly string[]; readonly handledButtonIds?: readonly string[];
readonly requiresVC?: boolean; readonly requiresVC?: boolean;
executeFromInteraction?: (interaction: CommandInteraction) => Promise<void>; execute: (interaction: CommandInteraction) => Promise<void>;
handleButtonInteraction?: (interaction: ButtonInteraction) => Promise<void>; handleButtonInteraction?: (interaction: ButtonInteraction) => Promise<void>;
} }

View file

@ -21,7 +21,7 @@ export default class implements Command {
this.playerManager = playerManager; this.playerManager = playerManager;
} }
public async executeFromInteraction(interaction: CommandInteraction) { public async execute(interaction: CommandInteraction) {
const player = this.playerManager.get(interaction.guild!.id); const player = this.playerManager.get(interaction.guild!.id);
if (player.status !== STATUS.PLAYING) { if (player.status !== STATUS.PLAYING) {

View file

@ -40,7 +40,7 @@ export default class implements Command {
} }
// eslint-disable-next-line complexity // eslint-disable-next-line complexity
public async executeFromInteraction(interaction: CommandInteraction): Promise<void> { public async execute(interaction: CommandInteraction): Promise<void> {
const [targetVoiceChannel] = getMemberVoiceChannel(interaction.member as GuildMember) ?? getMostPopularVoiceChannel(interaction.guild!); const [targetVoiceChannel] = getMemberVoiceChannel(interaction.member as GuildMember) ?? getMostPopularVoiceChannel(interaction.guild!);
const settings = await prisma.setting.findUnique({where: {guildId: interaction.guild!.id}}); const settings = await prisma.setting.findUnique({where: {guildId: interaction.guild!.id}});

View file

@ -23,7 +23,7 @@ export default class implements Command {
this.updatingQueueEmbedManager = updatingQueueEmbedManager; this.updatingQueueEmbedManager = updatingQueueEmbedManager;
} }
public async executeFromInteraction(interaction: CommandInteraction) { public async execute(interaction: CommandInteraction) {
const embed = this.updatingQueueEmbedManager.get(interaction.guild!.id); const embed = this.updatingQueueEmbedManager.get(interaction.guild!.id);
await embed.createFromInteraction(interaction); await embed.createFromInteraction(interaction);

View file

@ -27,7 +27,7 @@ export default class implements Command {
this.playerManager = playerManager; this.playerManager = playerManager;
} }
public async executeFromInteraction(interaction: CommandInteraction): Promise<void> { public async execute(interaction: CommandInteraction): Promise<void> {
const player = this.playerManager.get(interaction.guild!.id); const player = this.playerManager.get(interaction.guild!.id);
const position = interaction.options.getInteger('position') ?? 1; const position = interaction.options.getInteger('position') ?? 1;

View file

@ -26,7 +26,7 @@ export default class implements Command {
this.playerManager = playerManager; this.playerManager = playerManager;
} }
public async executeFromInteraction(interaction: CommandInteraction): Promise<void> { public async execute(interaction: CommandInteraction): Promise<void> {
const player = this.playerManager.get(interaction.guild!.id); const player = this.playerManager.get(interaction.guild!.id);
const currentSong = player.getCurrent(); const currentSong = player.getCurrent();

View file

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

View file

@ -20,7 +20,7 @@ export default class implements Command {
this.playerManager = playerManager; this.playerManager = playerManager;
} }
public async executeFromInteraction(interaction: CommandInteraction): Promise<void> { public async execute(interaction: CommandInteraction): Promise<void> {
const player = this.playerManager.get(interaction.guild!.id); const player = this.playerManager.get(interaction.guild!.id);
if (player.isQueueEmpty()) { if (player.isQueueEmpty()) {

View file

@ -1,9 +1,8 @@
import {CommandInteraction, Message, TextChannel} from 'discord.js'; import {CommandInteraction} from 'discord.js';
import {TYPES} from '../types.js'; import {TYPES} from '../types.js';
import {inject, injectable} from 'inversify'; import {inject, injectable} from 'inversify';
import PlayerManager from '../managers/player.js'; import PlayerManager from '../managers/player.js';
import Command from '.'; import Command from '.';
import LoadingMessage from '../utils/loading-message.js';
import errorMsg from '../utils/error-msg.js'; import errorMsg from '../utils/error-msg.js';
import {SlashCommandBuilder} from '@discordjs/builders'; import {SlashCommandBuilder} from '@discordjs/builders';
@ -32,7 +31,7 @@ export default class implements Command {
this.playerManager = playerManager; this.playerManager = playerManager;
} }
public async executeFromInteraction(interaction: CommandInteraction): Promise<void> { public async execute(interaction: CommandInteraction): Promise<void> {
const numToSkip = interaction.options.getInteger('skip') ?? 1; const numToSkip = interaction.options.getInteger('skip') ?? 1;
if (numToSkip < 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}); await interaction.reply({content: errorMsg('invalid number of songs to skip'), ephemeral: true});
} }
} }
public async execute(msg: Message, args: string []): Promise<void> {
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'));
}
}
} }

View file

@ -20,7 +20,7 @@ export default class implements Command {
this.playerManager = playerManager; this.playerManager = playerManager;
} }
public async executeFromInteraction(interaction: CommandInteraction): Promise<void> { public async execute(interaction: CommandInteraction): Promise<void> {
const player = this.playerManager.get(interaction.guild!.id); const player = this.playerManager.get(interaction.guild!.id);
try { try {

View file

@ -23,7 +23,6 @@ import Play from './commands/play.js';
import QueueCommand from './commands/queue.js'; import QueueCommand from './commands/queue.js';
import Remove from './commands/remove.js'; import Remove from './commands/remove.js';
import Seek from './commands/seek.js'; import Seek from './commands/seek.js';
import Shortcuts from './commands/shortcuts.js';
import Shuffle from './commands/shuffle.js'; import Shuffle from './commands/shuffle.js';
import Skip from './commands/skip.js'; import Skip from './commands/skip.js';
import Unskip from './commands/unskip.js'; import Unskip from './commands/unskip.js';
@ -63,7 +62,6 @@ container.bind<NaturalLanguage>(TYPES.Services.NaturalLanguage).to(NaturalLangua
QueueCommand, QueueCommand,
Remove, Remove,
Seek, Seek,
Shortcuts,
Shuffle, Shuffle,
Skip, Skip,
Unskip, Unskip,