From 759e93bec4e9e2eb86db7434007345c24b0a0252 Mon Sep 17 00:00:00 2001 From: TymanWasTaken Date: Sun, 16 May 2021 22:03:18 -0400 Subject: fix logging for slash command syncing v2, delete BotMessage and BotGuild because useless, add prefix slash command --- src/commands/admin/prefix.ts | 47 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 8 deletions(-) (limited to 'src/commands/admin') diff --git a/src/commands/admin/prefix.ts b/src/commands/admin/prefix.ts index 3948a7e..32af649 100644 --- a/src/commands/admin/prefix.ts +++ b/src/commands/admin/prefix.ts @@ -1,5 +1,7 @@ +import { ApplicationCommandOptionType } from 'discord-api-types'; +import { CommandInteraction, Message } from 'discord.js'; import { BotCommand } from '../../lib/extensions/BotCommand'; -import { BotMessage } from '../../lib/extensions/BotMessage'; +import { Guild } from '../../lib/models'; export default class PrefixCommand extends BotCommand { constructor() { @@ -16,21 +18,50 @@ export default class PrefixCommand extends BotCommand { 'Set the prefix of the current server (resets to default if prefix is not given)', usage: 'prefix [prefix]', examples: ['prefix', 'prefix +'] - } + }, + slashCommandOptions: [ + { + type: ApplicationCommandOptionType.STRING, + name: 'prefix', + description: 'The prefix to set for this server', + required: false + } + ] }); } - async exec( - message: BotMessage, - { prefix }: { prefix?: string } - ): Promise { + async exec(message: Message, { prefix }: { prefix?: string }): Promise { if (prefix) { - await message.settings.setPrefix(prefix); + const row = await Guild.findByPk(message.guild.id); + row.prefix = prefix; + await row.save(); await message.util.send(`Sucessfully set prefix to \`${prefix}\``); } else { - await message.settings.setPrefix(this.client.config.prefix); + const row = await Guild.findByPk(message.guild.id); + row.prefix = this.client.config.prefix; + await row.save(); await message.util.send( `Sucessfully reset prefix to \`${this.client.config.prefix}\`` ); } } + + async execSlash(message: CommandInteraction): Promise { + const prefix = message.options.find((o) => o.name === 'prefix')?.value as + | string + | undefined; + + 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