Skip to content

Commit 76ed688

Browse files
committed
fix(cop): Removed CopBot context management and rate limit notification functionality
1 parent 8684641 commit 76ed688

File tree

3 files changed

+2
-31
lines changed

3 files changed

+2
-31
lines changed

src/bot/index.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ export class CopBot {
1717
private webhookPath = `/bot/${Config.token}`;
1818
private webhookURL = `${Config.web_hook}${this.webhookPath}`;
1919
private mode = this.isProduction ? 'webhook' : 'long-polling';
20-
private static latestContext: Context | null = null;
2120
private constructor() {
2221
this._bot = new Bot<Context>(Config.token);
2322
}
@@ -28,19 +27,6 @@ export class CopBot {
2827
}
2928
return CopBot.instance;
3029
}
31-
public static setContext(ctx: Context): void {
32-
logger.info(`Setting new context: at ${new Date().toISOString()}`);
33-
this.latestContext = ctx;
34-
}
35-
36-
public static getContext(): Context | null {
37-
if (this.latestContext) {
38-
logger.info(`Retrieved latest context: at ${new Date().toISOString()}`);
39-
} else {
40-
logger.warn('Attempted to retrieve context, but no context is set.');
41-
}
42-
return this.latestContext;
43-
}
4430
// Stop the bot
4531
async stop(): Promise<void> {
4632
if (this.healthCheckInterval) {
@@ -131,10 +117,7 @@ export class CopBot {
131117
})
132118
);
133119
this._bot.on('my_chat_member', (ctx) => this.handleJoinNewChat(ctx));
134-
this._bot.on('message', (ctx) => {
135-
CopBot.setContext(ctx);
136-
this.handleMessage(ctx);
137-
});
120+
this._bot.on('message', (ctx) => this.handleMessage(ctx));
138121
this._bot.catch(async (error: BotError<Context>) => {
139122
if (error.message.includes('timeout')) {
140123
await error.ctx.reply('The request took too long to process. Please try again later.');

src/database/service/Database.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ export class DatabaseService {
1414
} catch (error: any) {
1515
console.error(`Error executing query: ${sql}`, error);
1616
throw new Error(`Database query failed: ${error.message}`);
17-
} finally {
18-
this._client.release();
1917
}
2018
}
2119
async insert<T extends QueryResultRow>(tableName: string, data: Record<string, any>, returning: string[] = ['*']): Promise<T> {

src/service/database/ServiceProvider.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,12 @@ export class ServiceProvider {
3232
return ServiceProvider.instance;
3333
}
3434
private async enforceRateLimit(): Promise<void> {
35-
const ctx = CopBot.getContext();
3635
const now = Date.now();
3736
if (this.lastRequestTime) {
3837
const elapsed = now - this.lastRequestTime;
3938
if (elapsed < this.requestInterval) {
4039
const waitTime = this.requestInterval - elapsed;
41-
42-
if (ctx) {
43-
try {
44-
await ctx.reply(`⚠️ Rate limit exceeded. Please wait for ${waitTime} ms before making another request.`);
45-
} catch (error: any) {
46-
logger.error(`Failed to notify user about rate limit: ${error.message}`);
47-
}
48-
} else {
49-
logger.warn('No active context to send a rate limit message.');
50-
}
40+
logger.error(`⚠️ Rate limit exceeded. Please wait for ${waitTime} ms before making another request.`);
5141
await new Promise((resolve) => setTimeout(resolve, waitTime));
5242
}
5343
}

0 commit comments

Comments
 (0)