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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 72 - (hide annotations)
Mon Jul 29 17:28:29 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 3609 byte(s)
Added proper help information
1 rakin 51 import { CommandInteraction, Interaction, Message } from 'discord.js';
2     import BaseCommand from '../../utils/structures/BaseCommand';
3     import DiscordClient from '../../client/Client';
4 rakin 72 import Help from '../../utils/Help';
5 rakin 51 import CommandOptions from '../../types/CommandOptions';
6     import InteractionOptions from '../../types/InteractionOptions';
7     import MessageEmbed from '../../client/MessageEmbed';
8 rakin 72 import { renderCommandList, renderCommandMeta } from '../../services/CommandMetaDataManager';
9 rakin 51
10     export default class HelpCommand extends BaseCommand {
11     constructor() {
12     super('help', 'settings', ['?']);
13     this.supportsInteractions = true;
14     }
15    
16     async render() {
17     let string = '';
18    
19 rakin 72 for (let cmd of Help) {
20 rakin 51 string += `\n\n**${cmd.name}**\n${cmd.shortBrief}`;
21     }
22    
23     return string;
24     }
25    
26     async run(client: DiscordClient, message: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {
27     if ((options.isInteraction && !options.options.getString('command')) || (!options.isInteraction && options.args[0] === undefined)) {
28     await message.reply({
29     embeds: [
30 rakin 72 new MessageEmbed({
31     title: 'Help',
32     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 rakin 51 ],
37     });
38    
39     return;
40     }
41    
42     const commandName = options.isInteraction ? options.options.getString('command') : options.args[0];
43 rakin 72 const cmd = Help.find(c => c.name === commandName);
44 rakin 51
45     if (!cmd) {
46     await message.reply({
47     embeds: [
48     new MessageEmbed()
49     .setColor('#f14a60')
50     .setDescription(`Invalid command \`${commandName}\`.`)
51     ]
52     });
53    
54     return;
55     }
56    
57 rakin 72 await message.reply({
58     embeds: [renderCommandMeta(cmd)]
59     });
60 rakin 51
61 rakin 72 // 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 rakin 51
72 rakin 72 // if (cmd.options !== undefined) {
73     // let str = '';
74 rakin 51
75 rakin 72 // for (let opt in cmd.options)
76     // str += `\`${opt}\` - ${cmd.options[opt]}\n`;
77 rakin 51
78 rakin 72 // str = str.substring(0, str.length - 1);
79 rakin 51
80 rakin 72 // fields.push({
81     // name: 'Options',
82     // value: str
83     // });
84     // }
85 rakin 51
86 rakin 72 // 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 rakin 51 }
102     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26