/[sudobot]/trunk/src/services/CommandMetaDataManager.ts
ViewVC logotype

Annotation of /trunk/src/services/CommandMetaDataManager.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 295 - (hide annotations)
Mon Jul 29 17:29:24 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 2209 byte(s)
feat: update help command
1 rakin 72 import DiscordClient from "../client/Client";
2     import MessageEmbed from "../client/MessageEmbed";
3     import { CommandHelpData } from "../types/CommandHelpData";
4     import Help from "../utils/Help";
5     import BaseCommand from "../utils/structures/BaseCommand";
6    
7     export function getAllCommandData() {
8     return Help;
9     }
10    
11     export function findCommandData(callback: (data: CommandHelpData) => boolean) {
12     return Help.find(callback);
13     }
14    
15 rakin 295 export function renderCommandList(limit = 40): string {
16 rakin 72 let str = `Type \`${DiscordClient.client.config.get('prefix')}help <CommandName>\` for more information about a specific command.\n\n`;
17 rakin 295 let index = 0;
18 rakin 72
19     for (const cmd of Help) {
20 rakin 295 if (limit <= index)
21     break;
22    
23 rakin 72 str += `**${cmd.name}**\n${cmd.shortBrief}\n\n`;
24 rakin 295 index++;
25 rakin 72 }
26    
27     return str;
28     }
29    
30     export function renderCommandMeta(cmd: CommandHelpData | string, commandObj?: BaseCommand): MessageEmbed {
31     let str = '';
32     const command = typeof cmd === 'string' ? findCommandData(c => c.name === cmd) : cmd;
33    
34     if (!command)
35     throw new Error('Command not found: ' + cmd);
36    
37     const cmdObj = commandObj ?? DiscordClient.client.commands.get(command.name)!;
38    
39     str += `${command.description ?? command.shortBrief}\n\n`;
40     str += `**Usage**\n\`${DiscordClient.client.config.get('prefix')}${command.name} ${command.structure}\`\n\n`;
41    
42     if (command.subcommands) {
43     str += `**Subcommands**\n`;
44    
45     for (let key in command.subcommands)
46     str += `\`${key}\` - ${command.subcommands[key]}\n`
47    
48     str += '\n\n';
49     }
50    
51     str += `**Examples**\n${command.example.replace(/\%\%/g, DiscordClient.client.config.get('prefix'))}\n\n`;
52     str += `**Legacy Commands Support**\n${command.legacyCommand ? 'Available' : 'Not supported'}\n\n`;
53     str += `**Slash Commands Support**\n${command.slashCommand ? 'Available' : 'Not supported'}\n\n`;
54     str += `**Category**\n\`${cmdObj.getCategory()}\`\n\n`;
55     str += `**Notes**\n${command.notes ?? '*No notes available*'}`;
56    
57     return new MessageEmbed({
58     author: {
59     name: `${DiscordClient.client.config.get('prefix')}${command.name}`
60     },
61     description: str
62     });
63     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26