Skip to content

Commit ef62c85

Browse files
committed
feat: add promote and demote cmd
1 parent d6eeac6 commit ef62c85

2 files changed

Lines changed: 72 additions & 0 deletions

File tree

src/commands/demote.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { Message } from "../../types/message";
2+
import log from "../components/utils/log";
3+
4+
export const info = {
5+
command: "demote",
6+
description: "Demote mentioned users from admin.",
7+
usage: "demote <@user>",
8+
example: "demote @user123",
9+
role: "admin",
10+
cooldown: 5000,
11+
};
12+
13+
export default async function (msg: Message) {
14+
if (msg.mentionedIds.length === 0) {
15+
await msg.reply("Please mention a user to demote.");
16+
return;
17+
}
18+
19+
const chat = await msg.getChat();
20+
21+
if (!chat.isGroup) {
22+
await msg.reply("This command only works in groups.");
23+
return;
24+
}
25+
26+
const groupChat = chat as any;
27+
28+
try {
29+
for (const userId of msg.mentionedIds) {
30+
await groupChat.demoteParticipants([userId]);
31+
}
32+
} catch (err) {
33+
log.error("Demote", err);
34+
await msg.reply("Failed to demote user. Make sure I am an admin.");
35+
}
36+
}

src/commands/promote.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { Message } from "../../types/message";
2+
import log from "../components/utils/log";
3+
4+
export const info = {
5+
command: "promote",
6+
description: "Promote mentioned users to admin.",
7+
usage: "promote <@user>",
8+
example: "promote @user123",
9+
role: "admin",
10+
cooldown: 5000,
11+
};
12+
13+
export default async function (msg: Message) {
14+
if (msg.mentionedIds.length === 0) {
15+
await msg.reply("Please mention a user to promote.");
16+
return;
17+
}
18+
19+
const chat = await msg.getChat();
20+
21+
if (!chat.isGroup) {
22+
await msg.reply("This command only works in groups.");
23+
return;
24+
}
25+
26+
const groupChat = chat as any;
27+
28+
try {
29+
for (const userId of msg.mentionedIds) {
30+
await groupChat.promoteParticipants([userId]);
31+
}
32+
} catch (err) {
33+
log.error("Promote", err);
34+
await msg.reply("Failed to promote user. Make sure I am an admin.");
35+
}
36+
}

0 commit comments

Comments
 (0)