Skip to content

Commit 84fe72a

Browse files
committed
merge: commits
2 parents 32bee49 + de91759 commit 84fe72a

39 files changed

Lines changed: 509 additions & 462 deletions

src/commands/admin.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/commands/block.ts

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { Message } from "../types/message";
2-
import { addBlockUser, deductUserPoints } from "../components/services/user";
2+
import {
3+
addBlockUser,
4+
deductUserPoints,
5+
getBlockUser,
6+
isAdmin,
7+
} from "../components/services/user";
8+
import client from "../components/client";
39

410
export const info = {
511
command: "block",
@@ -16,11 +22,33 @@ export default async function (msg: Message): Promise<void> {
1622
return;
1723
}
1824

19-
for (const userId of msg.mentionedIds) {
20-
const lid = userId.split("@")[0];
25+
const jid = msg.mentionedIds[0];
26+
const lid = jid.split("@")[0];
2127

22-
await Promise.allSettled([addBlockUser(lid), deductUserPoints(lid, 30)]);
28+
const self = (await client()).info.wid._serialized;
29+
const isUserAdmin = await isAdmin(lid);
30+
31+
if (!msg.fromMe && isUserAdmin) {
32+
await msg.reply("Unable to block the user.");
33+
return;
34+
}
35+
36+
const mentions = await msg.getMentions();
37+
const user = mentions[0];
38+
if (self.split("@")[0] === user.id._serialized.split("@")[0]) {
39+
await msg.reply("Unable to block the user.");
40+
return;
41+
}
42+
43+
const isBlocked = await getBlockUser(lid);
44+
if (isBlocked) {
45+
await msg.reply("The user is already blocked.");
46+
return;
2347
}
2448

25-
await msg.react("✅");
49+
await Promise.allSettled([
50+
addBlockUser(lid),
51+
deductUserPoints(lid, 30),
52+
msg.reply("The user has been blocked."),
53+
]);
2654
}

src/commands/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const info = {
99
description: "Build the bot (optionally clean before building).",
1010
usage: "build [--clean]",
1111
example: "build --clean",
12-
role: "super-admin",
12+
role: "admin",
1313
cooldown: 5000,
1414
};
1515

src/commands/bylaws.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { Message } from "../types/message";
2+
import log from "../components/utils/log";
3+
4+
export const info = {
5+
command: "bylaws",
6+
description: "Display the Bylaws of the bot.",
7+
usage: "bylaws",
8+
example: "bylaws",
9+
role: "legal",
10+
cooldown: 5000,
11+
};
12+
13+
export default async function (msg: Message): Promise<void> {
14+
const text = `
15+
\`Bot Bylaws\`
16+
These rules govern the use and responsibilities within this bot system.
17+
18+
━━━━━━━━━━━━━━━━━━━━━━━
19+
\`SuperAdmin (Bot Owner)\`
20+
- Full control over all bot operations and data
21+
- Can create, promote, or remove Admins and Legal roles
22+
- Has access to all logs, configurations, and override powers
23+
- Responsible for bot maintenance, updates, and critical decisions
24+
25+
\`Admin\`
26+
- Moderate bot interactions and enforce rules
27+
- Can mute, warn, or restrict users as necessary
28+
- Assist in managing bot commands and features
29+
- Cannot alter Legal or SuperAdmin permissions
30+
31+
\`Legal\`
32+
- Oversees legal usage, terms of service, and compliance
33+
- Handles copyright, data policy, and usage rights
34+
- May update the bylaws with SuperAdmin approval
35+
- Cannot manage users or bot configuration
36+
37+
\`User\`
38+
- May use commands within defined limitations
39+
- Must follow community guidelines and respect others
40+
- Misuse or abuse can lead to restrictions
41+
- Can report issues or violations to Admins or Legal
42+
43+
━━━━━━━━━━━━━━━━━━━━━━━
44+
All actions are logged and subject to review.
45+
By using this bot, you agree to follow these bylaws.
46+
47+
Last updated: October 2025
48+
`;
49+
50+
await msg.reply(text);
51+
}

src/commands/delete.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Message } from "../types/message"
1+
import { Message } from "../types/message";
22
import { client } from "../components/client";
33

44
export const info = {
@@ -11,13 +11,12 @@ export const info = {
1111
};
1212

1313
export default async function (msg: Message): Promise<void> {
14-
if (!msg.hasQuotedMsg) {
15-
await msg.reply("Please reply the message you want to delete.");
16-
return;
17-
}
14+
if (!msg.hasQuotedMsg) return;
15+
1816
const quoted = await msg.getQuotedMessage();
1917

2018
if (quoted.fromMe) {
19+
if (!msg.fromMe && /[aeiou]/i.test(quoted.body)) return;
2120
await quoted.delete(true, true);
2221
}
2322
}

src/commands/demote.ts

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,65 @@
1-
import { Message } from "../types/message"
1+
import { Message } from "../types/message";
22
import log from "../components/utils/log";
3+
import { isAdmin, setAdmin } from "../components/services/user";
4+
import client from "../components/client";
35

46
export const info = {
57
command: "demote",
6-
description: "Demote mentioned users from admin.",
8+
description: "Demote mentioned users from group or bot admin.",
79
usage: "demote <@user>",
810
example: "demote @user123",
9-
role: "admin",
11+
role: "super-admin",
1012
cooldown: 5000,
1113
};
1214

1315
export default async function (msg: Message): Promise<void> {
16+
const query = msg.body.replace(/^demote\b\s*/i, "").trim();
17+
18+
const bot = /--bot/i.test(query);
19+
const group = /--group/i.test(query);
20+
21+
if (!bot && !group) {
22+
await msg.reply("Please provide a valid flag: `--bot` or `--admin`.");
23+
return;
24+
}
25+
1426
if (msg.mentionedIds.length === 0) {
1527
await msg.reply("Please mention a user to demote.");
1628
return;
1729
}
1830

19-
const chat = await msg.getChat();
31+
if (group) {
32+
const chat = await msg.getChat();
33+
34+
if (!chat.isGroup) {
35+
await msg.reply("This command only works in groups.");
36+
return;
37+
}
38+
39+
const groupChat = chat as any;
2040

21-
if (!chat.isGroup) {
22-
await msg.reply("This command only works in groups.");
41+
try {
42+
for (const userId of msg.mentionedIds) {
43+
await groupChat.demoteParticipants([userId]);
44+
}
45+
} catch (err) {
46+
log.error("Demote", err);
47+
await msg.reply("Failed to demote user. Make sure I am an admin.");
48+
}
2349
return;
2450
}
2551

26-
const groupChat = chat as any;
52+
const jid = msg.mentionedIds[0];
53+
const lid = jid.split("@")[0];
2754

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.");
55+
const isUserAdmin = await isAdmin(lid);
56+
if (isUserAdmin) {
57+
await Promise.allSettled([
58+
setAdmin(lid, false),
59+
msg.reply("The user now demoted as bot admin."),
60+
]);
61+
return;
3562
}
63+
64+
await msg.reply("The user is not an admin.");
3665
}

src/commands/fbdl.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import log from "../components/utils/log";
66
import axios from "../components/axios";
77
import fs from "fs";
88
import he from "he";
9+
import { fileExists } from "../components/utils/file";
910

1011
export const info = {
1112
command: "fbdl",
@@ -16,15 +17,6 @@ export const info = {
1617
cooldown: 5000,
1718
};
1819

19-
const fileExists = async (filePath: string) => {
20-
try {
21-
await fs.promises.access(filePath, fs.constants.F_OK);
22-
return true;
23-
} catch {
24-
return false;
25-
}
26-
};
27-
2820
function md5FromUrl(url: string) {
2921
return crypto.createHash("md5").update(url).digest("hex");
3022
}

0 commit comments

Comments
 (0)