Implement command cooldown management and enhance command execution flow
- Introduced `applyCommandCooldown` function to manage per-command cooldowns after execution, improving command rate limiting. - Updated command execution flow to include cooldown application, ensuring users are informed of cooldown status. - Enhanced error handling in interaction replies, allowing for more graceful error management and user feedback. - Improved the handling of interaction responses across various commands, ensuring consistent user experience. - Added permission checks for new commands, ensuring only authorized users can execute specific actions.
This commit is contained in:
@@ -181,14 +181,29 @@ async function enqueueScheduleJob(
|
||||
return String(job.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a scheduled/failed job if present. Locked (active) jobs cannot be
|
||||
* removed — do not call this from inside the scheduleSend worker for the
|
||||
* job that is currently running.
|
||||
*/
|
||||
export async function removeScheduleJob(jobId: string | null): Promise<void> {
|
||||
if (!jobId) {
|
||||
return;
|
||||
}
|
||||
|
||||
const job = await scheduleQueue.getJob(jobId);
|
||||
if (job) {
|
||||
if (!job) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await job.remove();
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
if (message.includes('locked') || message.includes('could not be removed')) {
|
||||
logger.warn({ jobId, error }, 'Schedule job is locked; skipping remove');
|
||||
return;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -350,8 +365,10 @@ export async function sendScheduledMessage(context: BotContext, scheduleId: stri
|
||||
throw error;
|
||||
}
|
||||
|
||||
// One-shot: delete the DB row only. Do not remove the active BullMQ job
|
||||
// from inside its own worker (locked remove throws → retry → duplicate send).
|
||||
// removeOnComplete on enqueue cleans the job up after the processor returns.
|
||||
if (!schedule.cron) {
|
||||
await removeScheduleJob(schedule.jobId);
|
||||
await context.prisma.scheduledMessage.delete({ where: { id: scheduleId } });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user