/[sudobot]/trunk/src/commands/settings/HelpCommand.ts
ViewVC logotype

Contents of /trunk/src/commands/settings/HelpCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 51 - (show annotations)
Mon Jul 29 17:28:23 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 3218 byte(s)
Release version 2.0
1 import { CommandInteraction, Interaction, Message } from 'discord.js';
2 import BaseCommand from '../../utils/structures/BaseCommand';
3 import DiscordClient from '../../client/Client';
4 import Help from '../../utils/help';
5 import CommandOptions from '../../types/CommandOptions';
6 import InteractionOptions from '../../types/InteractionOptions';
7 import MessageEmbed from '../../client/MessageEmbed';
8
9 export default class HelpCommand extends BaseCommand {
10 constructor() {
11 super('help', 'settings', ['?']);
12 this.supportsInteractions = true;
13 }
14
15 async render() {
16 let string = '';
17
18 for (let cmd of Help.commands) {
19 string += `\n\n**${cmd.name}**\n${cmd.shortBrief}`;
20 }
21
22 return string;
23 }
24
25 async run(client: DiscordClient, message: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {
26 if ((options.isInteraction && !options.options.getString('command')) || (!options.isInteraction && options.args[0] === undefined)) {
27 await message.reply({
28 embeds: [
29 new MessageEmbed()
30 .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())
31 .setTitle('Help')
32 ],
33 });
34
35 return;
36 }
37
38 const commandName = options.isInteraction ? options.options.getString('command') : options.args[0];
39 const cmd = Help.commands.find(c => c.name === commandName);
40
41 if (!cmd) {
42 await message.reply({
43 embeds: [
44 new MessageEmbed()
45 .setColor('#f14a60')
46 .setDescription(`Invalid command \`${commandName}\`.`)
47 ]
48 });
49
50 return;
51 }
52
53 let fields = [
54 {
55 name: "Usage",
56 value: `\`${client.config.get('prefix')}${cmd.name}\`` + (cmd.structure.trim() !== '' ? ` \`${cmd.structure}\`` : '')
57 },
58 {
59 name: 'Examples',
60 value: cmd.example.replace(/\%\%/g, client.config.get('prefix'))
61 }
62 ];
63
64 if (cmd.options !== undefined) {
65 let str = '';
66
67 for (let opt in cmd.options)
68 str += `\`${opt}\` - ${cmd.options[opt]}\n`;
69
70 str = str.substring(0, str.length - 1);
71
72 fields.push({
73 name: 'Options',
74 value: str
75 });
76 }
77
78 if (cmd.notes !== null) {
79 fields.push({
80 name: "Notes",
81 value: cmd.notes
82 });
83 }
84
85 await message.reply({
86 embeds: [
87 new MessageEmbed()
88 .setTitle(`${client.config.get('prefix')}${cmd.name}`)
89 .setDescription("`<...>` means required argument, `[...]` means optional argument.\n\n" + (cmd.description !== null ? cmd.description : cmd.shortBrief))
90 .addFields(fields)
91 ]
92 });
93 }
94 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26