/[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 295 - (show annotations)
Mon Jul 29 17:29:24 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 3305 byte(s)
feat: update help command
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 import { renderCommandList, renderCommandMeta } from '../../services/CommandMetaDataManager';
9
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 for (let cmd of Help) {
20 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 new MessageEmbed({
31 title: 'Help',
32 description: renderCommandList()
33 })
34 ],
35 });
36
37 return;
38 }
39
40 const commandName = options.isInteraction ? options.options.getString('command') : options.args[0];
41 const cmd = Help.find(c => c.name === commandName);
42
43 if (!cmd) {
44 await message.reply({
45 embeds: [
46 new MessageEmbed()
47 .setColor('#f14a60')
48 .setDescription(`Invalid command \`${commandName}\`.`)
49 ]
50 });
51
52 return;
53 }
54
55 await message.reply({
56 embeds: [renderCommandMeta(cmd)]
57 });
58
59 // let fields = [
60 // {
61 // name: "Usage",
62 // value: `\`${client.config.get('prefix')}${cmd.name}\`` + (cmd.structure.trim() !== '' ? ` \`${cmd.structure}\`` : '')
63 // },
64 // {
65 // name: 'Examples',
66 // value: cmd.example.replace(/\%\%/g, client.config.get('prefix'))
67 // }
68 // ];
69
70 // if (cmd.options !== undefined) {
71 // let str = '';
72
73 // for (let opt in cmd.options)
74 // str += `\`${opt}\` - ${cmd.options[opt]}\n`;
75
76 // str = str.substring(0, str.length - 1);
77
78 // fields.push({
79 // name: 'Options',
80 // value: str
81 // });
82 // }
83
84 // if (cmd.notes !== null) {
85 // fields.push({
86 // name: "Notes",
87 // value: cmd.notes
88 // });
89 // }
90
91 // await message.reply({
92 // embeds: [
93 // new MessageEmbed()
94 // .setTitle(`${client.config.get('prefix')}${cmd.name}`)
95 // .setDescription("`<...>` means required argument, `[...]` means optional argument.\n\n" + (cmd.description !== null ? cmd.description : cmd.shortBrief))
96 // .addFields(fields)
97 // ]
98 // });
99 }
100 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26