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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 51 by rakin, Mon Jul 29 17:28:23 2024 UTC revision 549 by rakin, Mon Jul 29 17:30:46 2024 UTC
# Line 1  Line 1 
1  import { CommandInteraction, Interaction, Message } from 'discord.js';  /**
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    import { CommandInteraction, Message } from 'discord.js';
21  import BaseCommand from '../../utils/structures/BaseCommand';  import BaseCommand from '../../utils/structures/BaseCommand';
22  import DiscordClient from '../../client/Client';  import DiscordClient from '../../client/Client';
23  import Help from '../../utils/help';  import Help from '../../utils/Help';
24  import CommandOptions from '../../types/CommandOptions';  import CommandOptions from '../../types/CommandOptions';
25  import InteractionOptions from '../../types/InteractionOptions';  import InteractionOptions from '../../types/InteractionOptions';
26  import MessageEmbed from '../../client/MessageEmbed';  import MessageEmbed from '../../client/MessageEmbed';
27    import { getAllCommandData, renderCommandMeta } from '../../services/CommandMetaDataManager';
28    import Pagination from '../../utils/Pagination';
29    
30  export default class HelpCommand extends BaseCommand {  export default class HelpCommand extends BaseCommand {
31      constructor() {      constructor() {
# Line 15  export default class HelpCommand extends Line 36  export default class HelpCommand extends
36      async render() {      async render() {
37          let string = '';          let string = '';
38    
39          for (let cmd of Help.commands) {          for (let cmd of Help) {
40              string += `\n\n**${cmd.name}**\n${cmd.shortBrief}`;              string += `\n\n**${cmd.name}**\n${cmd.shortBrief}`;
41          }          }
42    
# Line 24  export default class HelpCommand extends Line 45  export default class HelpCommand extends
45    
46      async run(client: DiscordClient, message: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {      async run(client: DiscordClient, message: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {
47          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)) {
48              await message.reply({              const commandData = getAllCommandData();
49                  embeds: [              const pagination = new Pagination(commandData, {
50                      new MessageEmbed()                  channel_id: message.channel!.id,
51                      .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())                  guild_id: message.guild!.id,
52                      .setTitle('Help')                  limit: 10,
53                  ],                  user_id: message.member!.user.id,
54                    timeout: 120_000,
55                    embedBuilder({ data, maxPages, currentPage }) {
56                        let description = `\`<...>\` means required argument and \`[...]\` means optional argument.\nRun \`${client.config.get('prefix')}help <CommandName>\` for more information about a specific command.\n\n`;
57    
58                        for (const { name, shortBrief } of data) {
59                            description += `**${name}**\n`;
60                            description += `${shortBrief}\n\n`;
61                        }
62    
63                        return new MessageEmbed({
64                            author: {
65                                iconURL: client.user?.displayAvatarURL(),
66                                name: "Help"
67                            },
68                            description,
69                            footer: {
70                                text: `Page ${currentPage} of ${maxPages} • ${commandData.length} commands total`
71                            }
72                        });
73                    },
74              });              });
75    
76                let reply = await message.reply(pagination.getMessageOptions(1));
77    
78                if (message instanceof CommandInteraction) {
79                    reply = <Message> await message.fetchReply();
80                }
81    
82                await pagination.start(reply!);
83    
84              return;              return;
85          }          }
86    
87          const commandName = options.isInteraction ? options.options.getString('command') : options.args[0];          const commandName = options.isInteraction ? options.options.getString('command') : options.args[0];
88          const cmd = Help.commands.find(c => c.name === commandName);          const cmd = Help.find(c => c.name === commandName);
89    
90          if (!cmd) {          if (!cmd) {
91              await message.reply({              await message.reply({
# Line 50  export default class HelpCommand extends Line 99  export default class HelpCommand extends
99              return;              return;
100          }          }
101    
         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  
             });  
         }  
   
102          await message.reply({          await message.reply({
103              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)  
             ]  
104          });          });
105    
106            // let fields = [
107            //     {
108            //         name: "Usage",
109            //         value: `\`${client.config.get('prefix')}${cmd.name}\`` + (cmd.structure.trim() !== '' ? ` \`${cmd.structure}\`` : '')
110            //     },
111            //     {
112            //         name: 'Examples',
113            //         value: cmd.example.replace(/\%\%/g, client.config.get('prefix'))
114            //     }
115            // ];
116    
117            // if (cmd.options !== undefined) {
118            //     let str = '';
119    
120            //     for (let opt in cmd.options)
121            //         str += `\`${opt}\` - ${cmd.options[opt]}\n`;
122    
123            //     str = str.substring(0, str.length - 1);
124    
125            //     fields.push({
126            //         name: 'Options',
127            //         value: str
128            //     });
129            // }
130    
131            // if (cmd.notes !== null) {
132            //     fields.push({
133            //         name: "Notes",
134            //         value: cmd.notes
135            //     });
136            // }
137    
138            // await message.reply({
139            //     embeds: [
140            //         new MessageEmbed()
141            //         .setTitle(`${client.config.get('prefix')}${cmd.name}`)
142            //         .setDescription("`<...>` means required argument, `[...]` means optional argument.\n\n" + (cmd.description !== null ? cmd.description : cmd.shortBrief))
143            //         .addFields(fields)
144            //     ]
145            // });
146      }      }
 }  
147    }

Legend:
Removed from v.51  
changed lines
  Added in v.549

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26