Skip to content

Commit 8aefb84

Browse files
committed
chore: minor adjustments and changes
1 parent d67555c commit 8aefb84

6 files changed

Lines changed: 112 additions & 119 deletions

File tree

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/help.ts

Lines changed: 53 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -5,124 +5,101 @@ import { commands } from "../components/utils/cmd/loader";
55
export const info = {
66
command: "help",
77
description: "List available commands and their usage.",
8-
usage: "help [page|role|command]",
9-
example: "help admin",
8+
usage: "help [--role] [page|command]",
9+
example: "help --admin 2",
1010
role: "user",
1111
cooldown: 5000,
1212
};
1313

1414
type CommandType = {
1515
command: string;
1616
role: string;
17+
description?: string;
18+
usage?: string;
19+
example?: string;
20+
cooldown?: number;
1721
};
1822

1923
const PAGE_SIZE = 20;
24+
const validRoles = ["user", "admin", "super-admin", "legal"];
2025

2126
function paginate(items: string[], page: number, pageSize: number): string[] {
2227
const start = (page - 1) * pageSize;
2328
return items.slice(start, start + pageSize);
2429
}
2530

26-
function buildUserPage(
27-
userCommands: string[],
31+
function buildRoleHelpPage(
32+
commandsForRole: string[],
2833
page: number,
2934
totalPages: number,
35+
role: string,
3036
): string {
3137
let response = `
32-
\`Help ${page}\`
33-
help [command] for more details on a specific command.
38+
\`Help ${role.charAt(0).toUpperCase() + role.slice(1)}\`
39+
Use: *help [command]* for more details
3440
35-
| • ${userCommands.join("\n | • ") || "_None_"}
41+
| • ${commandsForRole.join("\n| • ") || "_None_"}
3642
3743
\`Page ${page} of ${totalPages}\`
3844
`;
3945
return response;
4046
}
4147

42-
function buildAdminPage(type: string, adminCommands: string[]): string {
43-
let response = `
44-
\`Help ${type}\`
45-
help [command] for more details on a specific command.
46-
47-
| • ${adminCommands.join("\n | • ") || "_None_"}
48-
`;
49-
return response;
50-
}
51-
5248
export default async function (msg: Message): Promise<void> {
53-
const match = /^help(?:\s+(admin|super-admin|\d+))?$/i.exec(msg.body.trim());
54-
if (!match) return;
55-
56-
const query = msg.body
57-
.replace(/^help\b\s*/i, "")
58-
.trim()
59-
.toLowerCase();
60-
61-
/*
62-
* will show help for a specific command
63-
*/
64-
const matchCommands = commands[query];
65-
if (matchCommands) {
49+
const query = msg.body.replace(/^help/i, "").trim();
50+
51+
// check if the query matches a specific command first
52+
const possibleCommand = query.split(/\s+/)[0];
53+
if (commands[possibleCommand]) {
54+
const cmd = commands[possibleCommand] as CommandType;
6655
const response = `
67-
\`${matchCommands.command}\`
68-
${matchCommands.description || "No description"}
56+
\`${cmd.command}\`
57+
${cmd.description || "No description"}
6958
70-
*Usage:* ${matchCommands.usage || "No usage"}
71-
*Example:* ${matchCommands.example || "No example"}
72-
*Role:* ${matchCommands.role || "User"}
73-
*Cooldown:* ${matchCommands.cooldown || 5000}ms
59+
*Usage:* ${cmd.usage || "N/A"}
60+
*Example:* ${cmd.example || "N/A"}
61+
*Role:* ${cmd.role}
62+
*Cooldown:* ${cmd.cooldown || 5000}ms
7463
`;
7564
await msg.reply(response);
7665
return;
7766
}
7867

79-
// help admin (group admins)
80-
if (/^admin$/i.test(query)) {
81-
const adminCommands = Object.values(commands)
82-
.filter((cmd: CommandType) => cmd.role === "admin")
83-
.map((cmd: CommandType) => cmd.command)
84-
.sort((a, b) => a.localeCompare(b));
85-
await msg.reply(buildAdminPage("Admin", adminCommands));
86-
return;
87-
}
88-
89-
// help super-admin (bot owner)
90-
if (/^super-admin$/i.test(query)) {
91-
const superCommands = Object.values(commands)
92-
.filter((cmd: CommandType) => cmd.role === "super-admin")
93-
.map((cmd: CommandType) => cmd.command)
94-
.sort((a, b) => a.localeCompare(b));
95-
await msg.reply(buildAdminPage("Super Admin", superCommands));
96-
return;
97-
}
98-
99-
if (!/^[1-9]\d*$/.test(query) && query != "") {
100-
await msg.reply("Please type a valid page number.");
101-
return;
68+
// extract role and page
69+
const args = query.split(/\s+/).filter(Boolean);
70+
let role = "user";
71+
let page = 1;
72+
73+
for (const arg of args) {
74+
if (arg.startsWith("--")) {
75+
const roleCandidate = arg.replace(/^--/, "").toLowerCase();
76+
if (validRoles.includes(roleCandidate)) {
77+
role = roleCandidate;
78+
}
79+
} else if (/^\d+$/.test(arg)) {
80+
page = parseInt(arg, 10);
81+
}
10282
}
10383

104-
// help [page]
105-
const matchPage = query.match(/(\d+)?/i);
106-
const page = Math.max(
107-
1,
108-
matchPage && matchPage[1] ? parseInt(matchPage[1], 10) : 1,
109-
);
110-
111-
const userCommands = Object.values(commands)
112-
.filter((cmd: CommandType) => cmd.role === "user")
84+
const filteredCommands = Object.values(commands)
85+
.filter((cmd: CommandType) => cmd.role === role)
11386
.map((cmd: CommandType) => cmd.command)
11487
.sort((a, b) => a.localeCompare(b));
11588

116-
userCommands.unshift("admin");
117-
userCommands.unshift("super-admin");
118-
119-
if (Object.values(commands).length === 0) {
120-
await msg.reply(`The *${page}* is obviously is not our bot bounds.`);
89+
if (filteredCommands.length === 0) {
90+
await msg.reply(`No commands found for role: *${role}*.`);
12191
return;
12292
}
12393

124-
const totalPages = Math.ceil(userCommands.length / PAGE_SIZE);
125-
const userPage = paginate(userCommands, page, PAGE_SIZE);
94+
const totalPages = Math.ceil(filteredCommands.length / PAGE_SIZE);
95+
if (page < 1 || page > totalPages) {
96+
await msg.reply(
97+
`Page *${page}* is out of range. Total pages: *${totalPages}*.`,
98+
);
99+
return;
100+
}
126101

127-
await msg.reply(buildUserPage(userPage, page, totalPages));
102+
const paginated = paginate(filteredCommands, page, PAGE_SIZE);
103+
const response = buildRoleHelpPage(paginated, page, totalPages, role);
104+
await msg.reply(response);
128105
}

src/commands/legal.ts

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

src/commands/update.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const info = {
99
description: "Pull changes from the remote repository and show commit info.",
1010
usage: "update",
1111
example: "update",
12-
role: "super-admin",
12+
role: "admin",
1313
cooldown: 5000,
1414
};
1515

src/components/events/message.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,11 @@ export default async function (msg: Message, type: string): Promise<void> {
211211
return;
212212
}
213213

214-
if (
215-
(rateLimitResult.status || rateLimitResult.value.timestamps.length > 5) &&
216-
!isUserAdmin
217-
) {
218-
await penalizeUser(lid, rateLimitResult.value);
214+
if (rateLimitResult.status || rateLimitResult.value.timestamps.length > 5) {
215+
await Promise.allSettled([
216+
penalizeUser(lid, rateLimitResult.value),
217+
msg.reply("You have been detected as spam, please wait for a while."),
218+
]);
219219
return;
220220
}
221221

@@ -229,7 +229,6 @@ export default async function (msg: Message, type: string): Promise<void> {
229229
return;
230230
}
231231

232-
233232
log.info("Message", lid, key);
234233
msg.body = newMessageBody;
235234

@@ -263,7 +262,7 @@ export default async function (msg: Message, type: string): Promise<void> {
263262
return await originalReply(messageBody, chatId, options);
264263
};
265264

266-
if (!msg.fromMe || !isUserAdmin) {
265+
if (!msg.fromMe) {
267266
const isInapproiateResponse = checkInappropriate(msg.body);
268267
if (isInapproiateResponse.isInappropriate) {
269268
const text =

0 commit comments

Comments
 (0)