aboutsummaryrefslogtreecommitdiff
path: root/src/commands/help.ts
diff options
context:
space:
mode:
authorMax Isom <[email protected]>2020-03-16 22:12:02 -0500
committerMax Isom <[email protected]>2020-03-16 22:12:02 -0500
commit426d0b03353906ecbd3d27ad25b9268e82ea2ab9 (patch)
tree636cb67a906bed2dc6b63c6b44f32e2a71fc0dc3 /src/commands/help.ts
parentac21b5657ba47ef9081c80424d5f8ae39b149f35 (diff)
downloadmuse-426d0b03353906ecbd3d27ad25b9268e82ea2ab9.tar.xz
muse-426d0b03353906ecbd3d27ad25b9268e82ea2ab9.zip
Add help command
Diffstat (limited to 'src/commands/help.ts')
-rw-r--r--src/commands/help.ts47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/commands/help.ts b/src/commands/help.ts
new file mode 100644
index 0000000..97cafa4
--- /dev/null
+++ b/src/commands/help.ts
@@ -0,0 +1,47 @@
+import {Message} from 'discord.js';
+import {injectable} from 'inversify';
+import Command from '.';
+import {TYPES} from '../types';
+import {Settings} from '../models';
+import container from '../inversify.config';
+
+@injectable()
+export default class implements Command {
+ public name = 'help';
+ public examples = [
+ ['help', 'you don\'t need a description']
+ ];
+
+ private commands: Command[] = [];
+
+ public async execute(msg: Message, _: string []): Promise<void> {
+ if (this.commands.length === 0) {
+ // Lazy load to avoid circular dependencies
+ this.commands = container.getAll<Command>(TYPES.Command);
+ }
+
+ const settings = await Settings.findOne({where: {guildId: msg.guild!.id}});
+
+ if (!settings) {
+ return;
+ }
+
+ const {prefix} = settings;
+
+ const res = this.commands.sort((a, b) => a.name.localeCompare(b.name)).reduce((content, command) => {
+ content += `**${command.name}**:\n`;
+
+ command.examples.forEach(example => {
+ content += `- \`${prefix}${example[0]}\`: ${example[1]}\n`;
+ });
+
+ content += '\n';
+
+ return content;
+ }, '');
+
+ await msg.author.send(res);
+ await msg.react('🇩');
+ await msg.react('🇲');
+ }
+}