/[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 393 - (hide annotations)
Mon Jul 29 17:29:59 2024 UTC (8 months, 2 weeks ago) by rakin
File MIME type: application/typescript
File size: 4016 byte(s)
style: add license comments (#77)

* style: add license commits

* fix: shebang errors
1 rakin 393 /**
2     * This file is part of SudoBot.
3     *
4     * Copyright (C) 2021-2022 OSN Inc.
5     *
6     * SudoBot is free software; you can redistribute it and/or modify it
7     * under the terms of the GNU Affero General Public License as published by
8     * the Free Software Foundation, either version 3 of the License, or
9     * (at your option) any later version.
10     *
11     * SudoBot is distributed in the hope that it will be useful, but
12     * WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU Affero General Public License for more details.
15     *
16     * You should have received a copy of the GNU Affero General Public License
17     * along with SudoBot. If not, see <https://www.gnu.org/licenses/>.
18     */
19    
20 rakin 344 import { CommandInteraction, Message } from 'discord.js';
21 rakin 51 import BaseCommand from '../../utils/structures/BaseCommand';
22     import DiscordClient from '../../client/Client';
23 rakin 72 import Help from '../../utils/Help';
24 rakin 51 import CommandOptions from '../../types/CommandOptions';
25     import InteractionOptions from '../../types/InteractionOptions';
26     import MessageEmbed from '../../client/MessageEmbed';
27 rakin 72 import { renderCommandList, renderCommandMeta } from '../../services/CommandMetaDataManager';
28 rakin 51
29     export default class HelpCommand extends BaseCommand {
30     constructor() {
31     super('help', 'settings', ['?']);
32     this.supportsInteractions = true;
33     }
34    
35     async render() {
36     let string = '';
37    
38 rakin 72 for (let cmd of Help) {
39 rakin 51 string += `\n\n**${cmd.name}**\n${cmd.shortBrief}`;
40     }
41    
42     return string;
43     }
44    
45     async run(client: DiscordClient, message: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {
46     if ((options.isInteraction && !options.options.getString('command')) || (!options.isInteraction && options.args[0] === undefined)) {
47     await message.reply({
48     embeds: [
49 rakin 72 new MessageEmbed({
50     title: 'Help',
51     description: renderCommandList()
52     })
53 rakin 51 ],
54     });
55    
56     return;
57     }
58    
59     const commandName = options.isInteraction ? options.options.getString('command') : options.args[0];
60 rakin 72 const cmd = Help.find(c => c.name === commandName);
61 rakin 51
62     if (!cmd) {
63     await message.reply({
64     embeds: [
65     new MessageEmbed()
66     .setColor('#f14a60')
67     .setDescription(`Invalid command \`${commandName}\`.`)
68     ]
69     });
70    
71     return;
72     }
73    
74 rakin 72 await message.reply({
75     embeds: [renderCommandMeta(cmd)]
76     });
77 rakin 51
78 rakin 72 // let fields = [
79     // {
80     // name: "Usage",
81     // value: `\`${client.config.get('prefix')}${cmd.name}\`` + (cmd.structure.trim() !== '' ? ` \`${cmd.structure}\`` : '')
82     // },
83     // {
84     // name: 'Examples',
85     // value: cmd.example.replace(/\%\%/g, client.config.get('prefix'))
86     // }
87     // ];
88 rakin 51
89 rakin 72 // if (cmd.options !== undefined) {
90     // let str = '';
91 rakin 51
92 rakin 72 // for (let opt in cmd.options)
93     // str += `\`${opt}\` - ${cmd.options[opt]}\n`;
94 rakin 51
95 rakin 72 // str = str.substring(0, str.length - 1);
96 rakin 51
97 rakin 72 // fields.push({
98     // name: 'Options',
99     // value: str
100     // });
101     // }
102 rakin 51
103 rakin 72 // if (cmd.notes !== null) {
104     // fields.push({
105     // name: "Notes",
106     // value: cmd.notes
107     // });
108     // }
109    
110     // await message.reply({
111     // embeds: [
112     // new MessageEmbed()
113     // .setTitle(`${client.config.get('prefix')}${cmd.name}`)
114     // .setDescription("`<...>` means required argument, `[...]` means optional argument.\n\n" + (cmd.description !== null ? cmd.description : cmd.shortBrief))
115     // .addFields(fields)
116     // ]
117     // });
118 rakin 51 }
119     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26