From 4d63c4af57a7391dd61106b79874b8e83c14971a Mon Sep 17 00:00:00 2001 From: TymanWasTaken Date: Sun, 16 May 2021 22:23:12 -0400 Subject: change all existing slash commands to have no repeating code, add help slash command --- src/commands/admin/prefix.ts | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'src/commands/admin') diff --git a/src/commands/admin/prefix.ts b/src/commands/admin/prefix.ts index 32af649..6d0273b 100644 --- a/src/commands/admin/prefix.ts +++ b/src/commands/admin/prefix.ts @@ -1,5 +1,5 @@ import { ApplicationCommandOptionType } from 'discord-api-types'; -import { CommandInteraction, Message } from 'discord.js'; +import { CommandInteraction, Message, Guild as DiscordGuild } from 'discord.js'; import { BotCommand } from '../../lib/extensions/BotCommand'; import { Guild } from '../../lib/models'; @@ -29,16 +29,24 @@ export default class PrefixCommand extends BotCommand { ] }); } - async exec(message: Message, { prefix }: { prefix?: string }): Promise { + + async changePrefix(guild: DiscordGuild, prefix?: string): Promise { if (prefix) { - const row = await Guild.findByPk(message.guild.id); + const row = await Guild.findByPk(guild.id); row.prefix = prefix; await row.save(); - await message.util.send(`Sucessfully set prefix to \`${prefix}\``); } else { - const row = await Guild.findByPk(message.guild.id); + const row = await Guild.findByPk(guild.id); row.prefix = this.client.config.prefix; await row.save(); + } + } + + async exec(message: Message, { prefix }: { prefix?: string }): Promise { + await this.changePrefix(message.guild, prefix); + if (prefix) { + await message.util.send(`Sucessfully set prefix to \`${prefix}\``); + } else { await message.util.send( `Sucessfully reset prefix to \`${this.client.config.prefix}\`` ); @@ -50,15 +58,10 @@ export default class PrefixCommand extends BotCommand { | string | undefined; + await this.changePrefix(message.guild, prefix); if (prefix) { - const row = await Guild.findByPk(message.guild.id); - row.prefix = prefix; - await row.save(); await message.reply(`Sucessfully set prefix to \`${prefix}\``); } else { - const row = await Guild.findByPk(message.guild.id); - row.prefix = this.client.config.prefix; - await row.save(); await message.reply( `Sucessfully reset prefix to \`${this.client.config.prefix}\`` ); -- cgit