eris/bot/cancelCommand.ts

14 lines
522 B
TypeScript
Raw Permalink Normal View History

2023-09-23 18:49:05 +00:00
import { generationQueue } from "../app/generationQueue.ts";
2023-09-24 13:08:35 +00:00
import { ErisContext } from "./mod.ts";
2023-09-18 15:51:19 +00:00
2023-09-24 13:08:35 +00:00
export async function cancelCommand(ctx: ErisContext) {
2023-09-22 02:59:22 +00:00
const jobs = await generationQueue.getAllJobs();
const userJobs = jobs
2023-09-22 23:40:21 +00:00
.filter((job) => job.lockUntil < new Date())
2023-09-22 02:59:22 +00:00
.filter((j) => j.state.from.id === ctx.from?.id);
for (const job of userJobs) await generationQueue.deleteJob(job.id);
2023-09-24 19:58:09 +00:00
await ctx.reply(`Cancelled ${userJobs.length} jobs`, {
reply_to_message_id: ctx.message?.message_id,
});
2023-09-18 15:51:19 +00:00
}