aboutsummaryrefslogtreecommitdiff
path: root/src/commands/dev/reload.ts
blob: 2d5b9d95c8f7da4cb4ee0d1875c0f1daa87d727c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { BotCommand, clientSendAndPermCheck, emojis, formatError, shell, type CommandMessage, type SlashMessage } from '#lib';

export default class ReloadCommand extends BotCommand {
	public constructor() {
		super('reload', {
			aliases: ['reload'],
			category: 'dev',
			description: 'Reloads the bot',
			usage: ['reload'],
			examples: ['reload'],
			ownerOnly: true,
			typing: true,
			slash: true,
			clientPermissions: (m) => clientSendAndPermCheck(m),
			userPermissions: []
		});
	}

	public override async exec(message: CommandMessage | SlashMessage) {
		if (!message.author.isOwner()) return await message.util.reply(`${emojis.error} Only my developers can run this command.`);

		let output: { stdout: string; stderr: string };
		try {
			const s = new Date();
			output = await shell(`yarn build`);
			await Promise.all([
				this.client.commandHandler.reloadAll(),
				this.client.listenerHandler.reloadAll(),
				this.client.inhibitorHandler.reloadAll(),
				this.client.contextMenuCommandHandler.reloadAll(),
				this.client.taskHandler.reloadAll()
			]);

			return message.util.send(`🔁 Successfully reloaded! (${new Date().getTime() - s.getTime()}ms)`);
		} catch (e) {
			if (output!) void this.client.logger.error('reloadCommand', output);
			return message.util.send(
				`An error occurred while reloading:\n${await this.client.utils.codeblock(formatError(e), 2048 - 34, 'js', true)}`
			);
		}
	}
}