-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelp.js
More file actions
82 lines (73 loc) · 2.5 KB
/
Copy pathhelp.js
File metadata and controls
82 lines (73 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const fs = require("fs");
module.exports = {
name: "help",
description: "Show a list of commands",
usage: "/help OR /help <command>",
example: "/help OR /help aur",
category: "Utilities",
handler: async (ctx) => {
const { message } = ctx;
const { text } = message;
if (text === "/help" || text === `/help@${ctx.me.username}`) {
const commandFiles = fs
.readdirSync(__dirname)
.filter((file) => file.endsWith(".js"));
const commands = [];
for (const file of commandFiles) {
const command = require(`./${file}`);
commands.push({
name: command.name,
description: command.description,
alias: command.alias,
category: command.category,
});
}
const categories = [];
for (const command of commands) {
if (!categories.includes(command.category)) {
categories.push(command.category);
}
}
let output =
"Here's the list of commands you can use, categorized by their category:\n\n";
for (const category of categories) {
output += `<b>${category}</b>:\n`;
for (const command of commands) {
if (command.category === category) {
output += `/${command.name}`;
if (command.alias) {
output += `, /${command.alias.join(", /")}`;
}
output += ` - ${command.description}\n`;
}
}
output += "\n";
}
await ctx.reply(output, { parse_mode: "HTML" });
} else if (text.substring(text.indexOf(" ") + 1)) {
const command = text.substring(text.indexOf(" ") + 1);
const commandFiles = fs
.readdirSync(__dirname)
.filter((file) => file.endsWith(".js"));
const commands = commandFiles.map((file) => require(`./${file}`));
const commandDetail = commands.find(
(cmd) =>
cmd.name === command || (cmd.alias && cmd.alias.includes(command))
);
if (commandDetail) {
let output = `*Command:* /${commandDetail.name}\n`;
output += `*Description:* ${commandDetail.description}\n`;
output += `*Usage:* \`${commandDetail.usage}\`\n`;
output += `*Example:* \`${commandDetail.example}\`\n`;
await ctx.reply(output, { parse_mode: "MarkdownV2" });
} else {
await ctx.reply(
`Command <code>${command}</code> not found!\nRun /help to see all the commands.`,
{
parse_mode: "HTML",
}
);
}
}
},
};