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 { renderCommandList, renderCommandMeta } from '../../services/CommandMetaDataManager'; |
28 |
|
|
29 |
export default class HelpCommand extends BaseCommand { |
export default class HelpCommand extends BaseCommand { |
30 |
constructor() { |
constructor() { |
35 |
async render() { |
async render() { |
36 |
let string = ''; |
let string = ''; |
37 |
|
|
38 |
for (let cmd of Help.commands) { |
for (let cmd of Help) { |
39 |
string += `\n\n**${cmd.name}**\n${cmd.shortBrief}`; |
string += `\n\n**${cmd.name}**\n${cmd.shortBrief}`; |
40 |
} |
} |
41 |
|
|
46 |
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)) { |
47 |
await message.reply({ |
await message.reply({ |
48 |
embeds: [ |
embeds: [ |
49 |
new MessageEmbed() |
new MessageEmbed({ |
50 |
.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()) |
title: 'Help', |
51 |
.setTitle('Help') |
description: renderCommandList() |
52 |
|
}) |
53 |
], |
], |
54 |
}); |
}); |
55 |
|
|
57 |
} |
} |
58 |
|
|
59 |
const commandName = options.isInteraction ? options.options.getString('command') : options.args[0]; |
const commandName = options.isInteraction ? options.options.getString('command') : options.args[0]; |
60 |
const cmd = Help.commands.find(c => c.name === commandName); |
const cmd = Help.find(c => c.name === commandName); |
61 |
|
|
62 |
if (!cmd) { |
if (!cmd) { |
63 |
await message.reply({ |
await message.reply({ |
71 |
return; |
return; |
72 |
} |
} |
73 |
|
|
|
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 |
|
|
}); |
|
|
} |
|
|
|
|
74 |
await message.reply({ |
await message.reply({ |
75 |
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) |
|
|
] |
|
76 |
}); |
}); |
77 |
|
|
78 |
|
// 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 |
|
|
89 |
|
// if (cmd.options !== undefined) { |
90 |
|
// let str = ''; |
91 |
|
|
92 |
|
// for (let opt in cmd.options) |
93 |
|
// str += `\`${opt}\` - ${cmd.options[opt]}\n`; |
94 |
|
|
95 |
|
// str = str.substring(0, str.length - 1); |
96 |
|
|
97 |
|
// fields.push({ |
98 |
|
// name: 'Options', |
99 |
|
// value: str |
100 |
|
// }); |
101 |
|
// } |
102 |
|
|
103 |
|
// 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 |
} |
} |
119 |
} |
} |