forked from pinks/eris
1
0
Fork 0
nyx/bot/cancelCommand.ts

15 lines
561 B
TypeScript
Raw 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-10-05 09:00:51 +00:00
allow_sending_without_reply: true,
2023-09-24 19:58:09 +00:00
});
2023-09-18 15:51:19 +00:00
}