Skip to content
This repository was archived by the owner on Sep 10, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 4 additions & 39 deletions src/screeningClient/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,8 @@ export class ScreeningClient {
worker: processScreening,
limit: 8,
});
private readonly cooldowns: Set<string> = new Set();

private async processCooldowns(
userId: string,
sendMessageOptions: MessageOptions
): Promise<boolean> {
if (this.cooldowns.has(userId)) {
const messageOptions = {
content:
"You are on cooldown! Please wait a minute before using this command again.",
ephemeral: true,
...sendMessageOptions,
};
await sendMessage(messageOptions);
return false;
} else {
this.cooldowns.add(userId);
return true;
}
}

private async dealWithQueue(params: ProcessParams, userId: string) {
private async dealWithQueue(params: ProcessParams) {
if (this.queue.willQueue()) {
const messageOptions: MessageOptions = {
content:
Expand All @@ -56,17 +36,8 @@ export class ScreeningClient {
}
const trueParams: ProcessParams = {
...params,
/*cooldown: {
container: this.cooldowns,
id: userId,
},*/
};
try {
await this.queue.enqueue(trueParams, 1);
} catch (e) {
this.cooldowns.delete(userId);
throw e;
}
await this.queue.enqueue(trueParams, 1);
}

public async queueAutoCommand(
Expand All @@ -81,9 +52,6 @@ export class ScreeningClient {
if (autoInfo === null) {
return;
}
if (!(await this.processCooldowns(userId, multiMessageParams))) {
return;
}
const processParams: ProcessParams = {
generateScreenshotParams: {
firstName: autoInfo.firstName,
Expand All @@ -98,16 +66,13 @@ export class ScreeningClient {
content: `<@${userId}>, here is the screenshot that you requested:`,
},
};
await this.dealWithQueue(processParams, userId);
await this.dealWithQueue(processParams);
}

public async queueOnceCommand(
userId: string,
params: ProcessParams
): Promise<void> {
if (!(await this.processCooldowns(userId, params.multiMessageParams))) {
return;
}
const deviceInfo = await getDeviceData({ userId: userId });
const processParams: ProcessParams = {
generateScreenshotParams: {
Expand All @@ -119,7 +84,7 @@ export class ScreeningClient {
content: `<@${userId}>, here is the screenshot that you requested:`,
},
};
await this.dealWithQueue(processParams, userId);
await this.dealWithQueue(processParams);
}

public async queueDailyAuto(
Expand Down