2023-09-23 18:49:05 +00:00
|
|
|
import { generationQueue } from "../app/generationQueue.ts";
|
2023-10-19 21:37:03 +00:00
|
|
|
import { omitUndef } from "../utils/omitUndef.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-10-19 21:37:03 +00:00
|
|
|
await ctx.reply(
|
|
|
|
`Cancelled ${userJobs.length} jobs`,
|
|
|
|
omitUndef({
|
|
|
|
reply_to_message_id: ctx.message?.message_id,
|
|
|
|
allow_sending_without_reply: true,
|
|
|
|
}),
|
|
|
|
);
|
2023-09-18 15:51:19 +00:00
|
|
|
}
|