diff options
author | TymanWasTaken <32660892+tymanwastaken@users.noreply.github.com> | 2021-05-28 21:54:50 -0600 |
---|---|---|
committer | TymanWasTaken <32660892+tymanwastaken@users.noreply.github.com> | 2021-05-28 21:54:50 -0600 |
commit | 2456dab3db0d8eaae515606b83a6c0c317d009b0 (patch) | |
tree | c20448112d43c1b4ffae1395584d9b202aeee3ed /src/commands/dev/reload.ts | |
parent | 1e9e334097702c68d871365fc016aa096d03c491 (diff) | |
parent | 5b5f0bf5667b922037508dfa88e40a1f8a2671ec (diff) | |
download | tanzanite-2456dab3db0d8eaae515606b83a6c0c317d009b0.tar.gz tanzanite-2456dab3db0d8eaae515606b83a6c0c317d009b0.tar.bz2 tanzanite-2456dab3db0d8eaae515606b83a6c0c317d009b0.zip |
fix conflicts
Diffstat (limited to 'src/commands/dev/reload.ts')
-rw-r--r-- | src/commands/dev/reload.ts | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/src/commands/dev/reload.ts b/src/commands/dev/reload.ts new file mode 100644 index 0000000..36c6fd7 --- /dev/null +++ b/src/commands/dev/reload.ts @@ -0,0 +1,69 @@ +import { BushCommand } from '../../lib/extensions/BushCommand'; +import { stripIndent } from 'common-tags'; +import { Message } from 'discord.js'; +import { CommandInteraction } from 'discord.js'; +import { SlashCommandOption } from '../../lib/extensions/Util'; +import { ApplicationCommandOptionType } from 'discord-api-types'; + +export default class ReloadCommand extends BushCommand { + constructor() { + super('reload', { + aliases: ['reload'], + category: 'dev', + description: { + content: 'Reloads the bot', + usage: 'reload', + examples: ['reload'] + }, + args: [ + { + id: 'fast', + match: 'flag', + flag: '--fast' + } + ], + ownerOnly: true, + typing: true, + slashCommandOptions: [ + { + type: ApplicationCommandOptionType.BOOLEAN, + name: 'fast', + description: 'Wheather to use esbuild for fast compiling or not', + required: false + } + ] + }); + } + + private async getResponse(fast: boolean): Promise<string> { + try { + const s = new Date(); + await this.client.util.shell(`yarn build-${fast ? 'esbuild' : 'tsc'}`); + this.client.commandHandler.reloadAll(); + this.client.listenerHandler.reloadAll(); + this.client.inhibitorHandler.reloadAll(); + return `🔁 Successfully reloaded! (${ + new Date().getTime() - s.getTime() + }ms)`; + } catch (e) { + return stripIndent` + An error occured while reloading: + ${await this.client.util.haste(e.stack)} + `; + } + } + + public async exec( + message: Message, + { fast }: { fast: boolean } + ): Promise<void> { + await message.util.send(await this.getResponse(fast)); + } + + public async execSlash( + message: CommandInteraction, + { fast }: { fast: SlashCommandOption<boolean> } + ): Promise<void> { + await message.reply(await this.getResponse(fast?.value)); + } +} |