Skip to content

Commit 8fb60d0

Browse files
committed
Add command handler to display user and admin commands
1 parent daad47d commit 8fb60d0

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

src/commands/cmd.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { Message } from "whatsapp-web.js";
2+
import log from "npmlog";
3+
import { commands } from "../index";
4+
5+
export const command = "cmd";
6+
export const role = "user";
7+
8+
export default async function (msg: Message) {
9+
try {
10+
const userCommands = Object.values(commands)
11+
.filter((cmd: any) => cmd.role === "user")
12+
.map((cmd: any) => cmd.command)
13+
.join(", ");
14+
15+
const adminCommands = Object.values(commands)
16+
.filter((cmd: any) => cmd.role === "admin")
17+
.map((cmd: any) => cmd.command)
18+
.join(", ");
19+
20+
let response = "*User:*\n" + userCommands;
21+
if (adminCommands) {
22+
response += "\n\n*Admin:*\n" + adminCommands;
23+
}
24+
25+
await msg.reply(response);
26+
} catch (error) {
27+
log.error("Command", "Error displaying commands:", error);
28+
await msg.reply("Failed to display commands.");
29+
}
30+
}

0 commit comments

Comments
 (0)