Skip to content

Commit c9e283b

Browse files
committed
Added legacy execution support to help command
1 parent 232ff47 commit c9e283b

File tree

2 files changed

+288
-18
lines changed

2 files changed

+288
-18
lines changed

src/Commands/General/help.js

Lines changed: 251 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,257 @@ export default new Command({
4545
requiredPermissions: { user: [], bot: [] },
4646
},
4747
LegacyRun: async (manager, message, args, prefixUsed, commandData) => {
48-
const lang = manager.configs.lang;
48+
const subCommand = args[0];
49+
const lang = manager.configs.lang,
50+
commandsConfig = manager.configs.commands;
51+
const slashCommands = manager.slashCommands,
52+
legacyCommands = manager.commands;
53+
54+
switch (subCommand) {
55+
case "category": {
56+
const type = args[1] || "general";
57+
const slashCommandsList = [
58+
...(await manager.application.commands.fetch()).toJSON(),
59+
...(await message.guild.commands.fetch()).toJSON(),
60+
],
61+
sortedCommands = legacyCommands
62+
.filter(
63+
(cmd) => cmd.commandData.Type?.toLowerCase() == type.toLowerCase()
64+
)
65+
?.toJSON();
66+
67+
const format = Object.entries(
68+
lang.General.Help.AutoCompleteCategory
69+
).find(([key]) => key.toLowerCase() == type.toLowerCase());
70+
const valueToUse = format && format[0] ? format[1] : type;
71+
72+
if (!sortedCommands.length)
73+
return message.reply(
74+
Utils.setupMessage({
75+
configPath: lang.General.Help.NoCommandsInCategory,
76+
variables: [
77+
...Utils.userVariables(message.member, "user"),
78+
{ searchFor: /{type}/g, replaceWith: type },
79+
],
80+
})
81+
);
82+
83+
const messages = [],
84+
maxPages = Math.ceil(sortedCommands.length / 10),
85+
pageIndex = 0;
86+
if (maxPages == 1) {
87+
message.reply(
88+
Utils.setupMessage({
89+
configPath: lang.General.Help.CommandList,
90+
variables: [
91+
...Utils.userVariables(message.member, "user"),
92+
{ searchFor: /{max-page}/g, replaceWith: maxPages },
93+
{ searchFor: /{current-page}/g, replaceWith: 1 },
94+
{ searchFor: /{category}/g, replaceWith: valueToUse },
95+
{
96+
searchFor: /{data}/g,
97+
replaceWith: sortedCommands
98+
.map((cmd, i) => {
99+
const slashCmd = slashCommandsList.find(
100+
(x) => x.name == cmd.commandData.Name
101+
);
102+
return [
103+
`\`${i + 1}]\` **${Utils.capitalizeFirstLetter(
104+
cmd.commandData.Name
105+
)}** - ${cmd.commandData.Description}`,
106+
getOptions(slashCmd),
107+
]
108+
.filter((x) => x)
109+
.join("\n");
110+
})
111+
.join("\n\n"),
112+
},
113+
],
114+
})
115+
);
116+
} else {
117+
for (let i = 0; i < maxPages; i++) {
118+
const cmds = Utils.paginateArray(sortedCommands, 10, i + 1);
119+
messages.push(
120+
Utils.setupMessage({
121+
configPath: lang.General.Help.CommandList,
122+
variables: [
123+
...Utils.userVariables(message.member, "user"),
124+
{ searchFor: /{max-page}/g, replaceWith: maxPages },
125+
{ searchFor: /{current-page}/g, replaceWith: i + 1 },
126+
{ searchFor: /{category}/g, replaceWith: valueToUse },
127+
{
128+
searchFor: /{data}/g,
129+
replaceWith: cmds
130+
.map((cmd, i) => {
131+
const slashCmd = slashCommandsList.find(
132+
(x) => x.name == cmd.commandData.Name
133+
);
134+
return [
135+
`\`${i + 1}]\` **${Utils.capitalizeFirstLetter(
136+
cmd.commandData.Name
137+
)}** - ${cmd.commandData.Description}`,
138+
getOptions(slashCmd),
139+
]
140+
.filter((x) => x)
141+
.join("\n");
142+
})
143+
.join("\n\n"),
144+
},
145+
],
146+
})
147+
);
148+
}
149+
150+
const getRow = (disabled) =>
151+
new Discord.ActionRowBuilder().addComponents([
152+
new Discord.ButtonBuilder({
153+
customId: "bryanbot_help_next",
154+
style: 1,
155+
emoji: "⏮",
156+
}).setDisabled(disabled ? disabled : pageIndex == 0),
157+
new Discord.ButtonBuilder({
158+
customId: "bryanbot_help_last",
159+
style: 1,
160+
emoji: "⏭",
161+
}).setDisabled(
162+
disabled ? disabled : pageIndex == messages.length - 1
163+
),
164+
]);
165+
let queueMSG = { ...messages[pageIndex], components: [getRow()] };
166+
167+
message.reply(queueMSG).then(async (msg) => {
168+
const collector = await msg.createMessageComponentCollector({
169+
filter: (i) => i.user.id == message.author.id,
170+
time: 2 * 60 * 1000,
171+
componentType: "BUTTON",
172+
});
173+
collector.on("collect", async (interaction) => {
174+
if (
175+
!["bryanbot_help_next", "bryanbot_help_last"].includes(
176+
interaction.customId
177+
)
178+
)
179+
return;
180+
181+
if (
182+
interaction.customId == "bryanbot_help_last" &&
183+
pageIndex > 0
184+
) {
185+
--pageIndex;
186+
} else if (
187+
interaction.customId == "bryanbot_help_next" &&
188+
pageIndex < maxPages - 1
189+
) {
190+
++pageIndex;
191+
}
192+
193+
interaction.update({
194+
...messages[pageIndex],
195+
components: [getRow()],
196+
});
197+
});
198+
199+
collector.on("end", async () =>
200+
msg.edit({ ...messages[pageIndex], components: [getRow(true)] })
201+
);
202+
});
203+
}
204+
205+
break;
206+
}
207+
case "command": {
208+
const command = args[1] || "help";
209+
210+
const legacyCommand = legacyCommands.get(command),
211+
slashCommandsList = [
212+
...(await manager.application.commands.fetch()).toJSON(),
213+
...(await message.guild.commands.fetch()).toJSON(),
214+
];
215+
216+
const slashCommandApplication = slashCommandsList.find(
217+
(cmd) => cmd.name === command
218+
);
219+
220+
if (!legacyCommand)
221+
return message.reply(
222+
Utils.setupMessage({
223+
configPath: lang.General.Help.CommandNotFound,
224+
variables: Utils.userVariables(message.member, "user"),
225+
})
226+
);
227+
228+
const commandData = legacyCommand.commandData;
229+
if (!Array.isArray(commandData.Permission))
230+
commandData.Permission = [commandData.Permission];
231+
const commandVariables = [
232+
{ searchFor: /{prefixUsed}/g, replaceWith: "/" },
233+
{ searchFor: /{cmd-name}/g, replaceWith: commandData.Name },
234+
{ searchFor: /{cmd-type}/g, replaceWith: commandData.Type },
235+
{ searchFor: /{cmd-usage}/g, replaceWith: commandData.Usage },
236+
{
237+
searchFor: /{cmd-cooldown}/g,
238+
replaceWith: commandData.Cooldown ? ms(commandData.Cooldown) : "❎",
239+
},
240+
{
241+
searchFor: /{cmd-description}/g,
242+
replaceWith: commandData.Description,
243+
},
244+
{
245+
searchFor: /{cmd-dmOnly}/g,
246+
replaceWith: legacyCommand.commandConfig.dmOnly ? "✅" : "❎",
247+
},
248+
{
249+
searchFor: /{cmd-guildOnly}/g,
250+
replaceWith: legacyCommand.commandConfig.guildOnly ? "✅" : "❎",
251+
},
252+
{
253+
searchFor: /{cmd-isSlashCommand}/g,
254+
replaceWith: Array.isArray(commandData.Arguments) ? "✅" : "❎",
255+
},
256+
{
257+
searchFor: /{cmd-slashMentions}/g,
258+
replaceWith: slashCommandApplication
259+
? getOptions(slashCommandApplication)
260+
: "❎",
261+
},
262+
{
263+
searchFor: /{cmd-permission}/g,
264+
replaceWith: commandData.Permission.map((role) => {
265+
if (role === "@everyone") return `@everyone`;
266+
267+
const guildRole = Utils.findRole(message.guild, role, true);
268+
if (guildRole) return guildRole.toString();
269+
}).join(", "),
270+
},
271+
];
272+
273+
message.reply(
274+
Utils.setupMessage({
275+
configPath: lang.General.Help.CommandInfo,
276+
variables: [
277+
...Utils.userVariables(message.member, "user"),
278+
...commandVariables,
279+
],
280+
})
281+
);
282+
break;
283+
}
284+
default: {
285+
message.reply(
286+
Utils.setupMessage({
287+
configPath: lang.General.Help.InvalidUsage,
288+
variables: [
289+
...Utils.botVariables(manager),
290+
...Utils.guildVariables(message.guild),
291+
...Utils.userVariables(message.member),
292+
...Utils.channelVariables(message.channel),
293+
{ searchFor: /{prefixUsed}/, replaceWith: prefixUsed },
294+
],
295+
})
296+
);
297+
}
298+
}
49299
},
50300
InteractionRun: async (manager, interaction, commandData) => {
51301
const subCommand = interaction.options.getSubcommand();

src/Configs/lang.js

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const LangType = {
88
TagEmbed: SetupMessage,
99
Presets: {
1010
Error: SetupMessage,
11-
CommandError: SetupMessage
11+
CommandError: SetupMessage,
1212
},
1313
General: {
1414
Info: {
@@ -18,6 +18,7 @@ const LangType = {
1818
InvalidUsage: SetupMessage,
1919
},
2020
Help: {
21+
InvalidUsage: SetupMessage,
2122
AutoCompleteCategory: {
2223
[String]: String,
2324
},
@@ -47,21 +48,22 @@ const defaultConfig = {
4748
Color: "#ef1e13",
4849
Footer: "{brand-name} Error Handler",
4950
FooterIcon: "{brand-logo}",
50-
Timestamp: true
51-
}
52-
]
51+
Timestamp: true,
52+
},
53+
],
5354
},
5455
CommandError: {
5556
Embeds: [
5657
{
57-
Description: "### There was a problem executing this command.\n{error}",
58+
Description:
59+
"### There was a problem executing this command.\n{error}",
5860
Color: "#ef1e13",
5961
Footer: "{brand-name} Error Handler",
6062
FooterIcon: "{brand-logo}",
61-
Timestamp: true
62-
}
63-
]
64-
}
63+
Timestamp: true,
64+
},
65+
],
66+
},
6567
},
6668
TagEmbed: {
6769
Embeds: [
@@ -106,21 +108,20 @@ const defaultConfig = {
106108
{
107109
Name: "📥 Input",
108110
Value: "```js\n{input}```",
109-
Inline: false
111+
Inline: false,
110112
},
111113
{
112114
Name: "📤 Output",
113115
Value: "```js\n{output}```",
114-
Inline: false
115-
}
116+
Inline: false,
117+
},
116118
],
117119
Footer: "{brand-name} | Secure Execution",
118120
FooterIcon: "{brand-logo}",
119-
Timestamp: true
120-
}
121-
]
122-
123-
}
121+
Timestamp: true,
122+
},
123+
],
124+
},
124125
},
125126
General: {
126127
Info: {
@@ -278,6 +279,25 @@ const defaultConfig = {
278279
},
279280
},
280281
Help: {
282+
InvalidUsage: {
283+
Embeds: [
284+
{
285+
Author: "{brand-name} | Invalid Usage",
286+
AuthorIcon: "{brand-logo}",
287+
Description:
288+
"> {user-mention}, you have to specify a valid type of information to show. Valid types are: `category` and `command`.",
289+
Fields: [
290+
{
291+
Name: "• Usage",
292+
Value: "> `{prefixUsed}help <category/command> [parameter]`",
293+
},
294+
],
295+
FooterIcon: "{user-pfp}",
296+
Footer: "{user-tag}",
297+
Timestamp: true,
298+
},
299+
],
300+
},
281301
AutoCompleteCategory: {
282302
General: "General Commands 🌏",
283303
},

0 commit comments

Comments
 (0)