Skip to content

Commit ba1bfa5

Browse files
committed
feat(commands): Added new commands 'aran' and 'codeTime' to Command class, updated imports and logger configuration, and modified existing command logic.
1 parent 1b95019 commit ba1bfa5

2 files changed

Lines changed: 70 additions & 1 deletion

File tree

src/controller/command.ts

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,18 @@ import { AdminCommand } from "../group-management/AdminCommand";
66
import { Logger } from "../config/logger";
77
import { RateLimiter } from "../helper/RateLimiter";
88
import { initGroupSetting } from "../decorators/db";
9+
import * as roastMessages from "../helper/roast.json";
10+
import { RoastMessages } from "../types";
11+
912
const logger = new Logger({
1013
file: "command.log",
1114
level: "debug",
1215
timestampFormat: "locale",
1316
});
1417

1518
export class Command {
19+
private static aranState: Map<number, number> = new Map();
20+
1621
@SafeExecution()
1722
static start(ctx: Context) {
1823
if (ctx.chat?.type === "private") {
@@ -41,7 +46,7 @@ export class Command {
4146
await ctx.reply("دوستان.");
4247
setTimeout(() => {
4348
return ctx.reply("بحث تخصصی.");
44-
}, 2500);
49+
}, 2000);
4550
}
4651
@SafeExecution()
4752
static future(ctx: Context) {
@@ -72,7 +77,69 @@ export class Command {
7277
});
7378
}
7479
}
80+
@SafeExecution()
81+
static async aran(ctx: Context) {
82+
const userId = ctx.from?.id;
83+
if (!userId) return;
84+
85+
const currentState = Command.aranState.get(userId) || 0;
86+
87+
switch (currentState) {
88+
case 0:
89+
await ctx.reply("Aran mode: Activated.");
90+
Command.aranState.set(userId, 1);
91+
break;
92+
case 1:
93+
await ctx.reply("رفرنس بده.");
94+
Command.aranState.set(userId, 2);
95+
break;
96+
case 2:
97+
await ctx.reply("Aran mode: deActivated.");
98+
Command.aranState.set(userId, 0);
99+
break;
100+
default:
101+
Command.aranState.set(userId, 0);
102+
break;
103+
}
104+
}
105+
@SafeExecution()
106+
static async codeTime(ctx: Context) {
107+
const user = ctx.from;
108+
if (!user) return;
75109

110+
const targetUser = ctx.message?.reply_to_message?.from;
111+
112+
const randomHours = (min: number, max: number) => {
113+
return Math.floor(Math.random() * (max - min + 1)) + min;
114+
};
115+
// Function to get a random message from the appropriate category
116+
const getRandomMessage = (category: keyof RoastMessages) => {
117+
const messages = roastMessages[category];
118+
const randomIndex = Math.floor(Math.random() * messages.length);
119+
return messages[randomIndex];
120+
};
121+
if (targetUser?.id === ctx.me?.id) {
122+
const hours = randomHours(7, 10);
123+
const message = getRandomMessage("replyToBot").replace("{hours}", hours.toString());
124+
return await ctx.reply(message, {
125+
reply_to_message_id: ctx.message?.message_id,
126+
});
127+
}
128+
if (targetUser) {
129+
const hours = randomHours(3, 10);
130+
const username = targetUser.username
131+
? `@${targetUser.username}`
132+
: targetUser.first_name;
133+
const message = getRandomMessage("replyToUser").replace("{username}", username).replace("{hours}", hours.toString());
134+
await ctx.reply(message, {
135+
reply_to_message_id: ctx.message?.message_id,
136+
});
137+
} else {
138+
const hours = randomHours(1, 7);
139+
const message = getRandomMessage("notReplyingToAnyone").replace("{hours}", hours.toString());
140+
await ctx.reply(message);
141+
}
142+
}
76143
// This method is now called only once, during initialization
77144
static generate() {
78145
for (const command of COMMANDS) {

src/helper/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ export const COMMANDS: string[] = [
6363
"rules",
6464
"approvedList",
6565
"shahin",
66+
"aran",
67+
"codeTime"
6668
];
6769
export async function executeService(ctx: Context,service: any,method: string) {
6870
if (service[method]) {

0 commit comments

Comments
 (0)