1 |
import { CommandInteraction, Interaction, Message } from 'discord.js'; |
import { CommandInteraction, Interaction, Message } from 'discord.js'; |
2 |
import BaseCommand from '../../utils/structures/BaseCommand'; |
import BaseCommand from '../../utils/structures/BaseCommand'; |
3 |
import DiscordClient from '../../client/Client'; |
import DiscordClient from '../../client/Client'; |
4 |
import Help from '../../utils/help'; |
import Help from '../../utils/Help'; |
5 |
import CommandOptions from '../../types/CommandOptions'; |
import CommandOptions from '../../types/CommandOptions'; |
6 |
import InteractionOptions from '../../types/InteractionOptions'; |
import InteractionOptions from '../../types/InteractionOptions'; |
7 |
import MessageEmbed from '../../client/MessageEmbed'; |
import MessageEmbed from '../../client/MessageEmbed'; |
8 |
|
import { renderCommandList, renderCommandMeta } from '../../services/CommandMetaDataManager'; |
9 |
|
|
10 |
export default class HelpCommand extends BaseCommand { |
export default class HelpCommand extends BaseCommand { |
11 |
constructor() { |
constructor() { |
16 |
async render() { |
async render() { |
17 |
let string = ''; |
let string = ''; |
18 |
|
|
19 |
for (let cmd of Help.commands) { |
for (let cmd of Help) { |
20 |
string += `\n\n**${cmd.name}**\n${cmd.shortBrief}`; |
string += `\n\n**${cmd.name}**\n${cmd.shortBrief}`; |
21 |
} |
} |
22 |
|
|
27 |
if ((options.isInteraction && !options.options.getString('command')) || (!options.isInteraction && options.args[0] === undefined)) { |
if ((options.isInteraction && !options.options.getString('command')) || (!options.isInteraction && options.args[0] === undefined)) { |
28 |
await message.reply({ |
await message.reply({ |
29 |
embeds: [ |
embeds: [ |
30 |
new MessageEmbed() |
new MessageEmbed({ |
31 |
.setDescription("The command list.\n\n`<...>` means required argument, `[...]` means optional argument.\n\nRun `" + client.config.get('prefix') + "help <commandName>` for more information about a specific command.\n" + await this.render()) |
title: 'Help', |
32 |
.setTitle('Help') |
description: renderCommandList() |
33 |
|
}) |
34 |
|
// .setDescription("The command list.\n\n`<...>` means required argument, `[...]` means optional argument.\n\nRun `" + client.config.get('prefix') + "help <commandName>` for more information about a specific command.\n" + await this.render()) |
35 |
|
// .setTitle('Help') |
36 |
], |
], |
37 |
}); |
}); |
38 |
|
|
40 |
} |
} |
41 |
|
|
42 |
const commandName = options.isInteraction ? options.options.getString('command') : options.args[0]; |
const commandName = options.isInteraction ? options.options.getString('command') : options.args[0]; |
43 |
const cmd = Help.commands.find(c => c.name === commandName); |
const cmd = Help.find(c => c.name === commandName); |
44 |
|
|
45 |
if (!cmd) { |
if (!cmd) { |
46 |
await message.reply({ |
await message.reply({ |
54 |
return; |
return; |
55 |
} |
} |
56 |
|
|
|
let fields = [ |
|
|
{ |
|
|
name: "Usage", |
|
|
value: `\`${client.config.get('prefix')}${cmd.name}\`` + (cmd.structure.trim() !== '' ? ` \`${cmd.structure}\`` : '') |
|
|
}, |
|
|
{ |
|
|
name: 'Examples', |
|
|
value: cmd.example.replace(/\%\%/g, client.config.get('prefix')) |
|
|
} |
|
|
]; |
|
|
|
|
|
if (cmd.options !== undefined) { |
|
|
let str = ''; |
|
|
|
|
|
for (let opt in cmd.options) |
|
|
str += `\`${opt}\` - ${cmd.options[opt]}\n`; |
|
|
|
|
|
str = str.substring(0, str.length - 1); |
|
|
|
|
|
fields.push({ |
|
|
name: 'Options', |
|
|
value: str |
|
|
}); |
|
|
} |
|
|
|
|
|
if (cmd.notes !== null) { |
|
|
fields.push({ |
|
|
name: "Notes", |
|
|
value: cmd.notes |
|
|
}); |
|
|
} |
|
|
|
|
57 |
await message.reply({ |
await message.reply({ |
58 |
embeds: [ |
embeds: [renderCommandMeta(cmd)] |
|
new MessageEmbed() |
|
|
.setTitle(`${client.config.get('prefix')}${cmd.name}`) |
|
|
.setDescription("`<...>` means required argument, `[...]` means optional argument.\n\n" + (cmd.description !== null ? cmd.description : cmd.shortBrief)) |
|
|
.addFields(fields) |
|
|
] |
|
59 |
}); |
}); |
60 |
|
|
61 |
|
// let fields = [ |
62 |
|
// { |
63 |
|
// name: "Usage", |
64 |
|
// value: `\`${client.config.get('prefix')}${cmd.name}\`` + (cmd.structure.trim() !== '' ? ` \`${cmd.structure}\`` : '') |
65 |
|
// }, |
66 |
|
// { |
67 |
|
// name: 'Examples', |
68 |
|
// value: cmd.example.replace(/\%\%/g, client.config.get('prefix')) |
69 |
|
// } |
70 |
|
// ]; |
71 |
|
|
72 |
|
// if (cmd.options !== undefined) { |
73 |
|
// let str = ''; |
74 |
|
|
75 |
|
// for (let opt in cmd.options) |
76 |
|
// str += `\`${opt}\` - ${cmd.options[opt]}\n`; |
77 |
|
|
78 |
|
// str = str.substring(0, str.length - 1); |
79 |
|
|
80 |
|
// fields.push({ |
81 |
|
// name: 'Options', |
82 |
|
// value: str |
83 |
|
// }); |
84 |
|
// } |
85 |
|
|
86 |
|
// if (cmd.notes !== null) { |
87 |
|
// fields.push({ |
88 |
|
// name: "Notes", |
89 |
|
// value: cmd.notes |
90 |
|
// }); |
91 |
|
// } |
92 |
|
|
93 |
|
// await message.reply({ |
94 |
|
// embeds: [ |
95 |
|
// new MessageEmbed() |
96 |
|
// .setTitle(`${client.config.get('prefix')}${cmd.name}`) |
97 |
|
// .setDescription("`<...>` means required argument, `[...]` means optional argument.\n\n" + (cmd.description !== null ? cmd.description : cmd.shortBrief)) |
98 |
|
// .addFields(fields) |
99 |
|
// ] |
100 |
|
// }); |
101 |
} |
} |
102 |
} |
} |