diff --git a/bot/cancelCommand.ts b/bot/cancelCommand.ts new file mode 100644 index 0000000..5c8133a --- /dev/null +++ b/bot/cancelCommand.ts @@ -0,0 +1,9 @@ +import { jobStore } from "../db/jobStore.ts"; +import { Context } from "./mod.ts"; + +export async function cancelCommand(ctx: Context) { + const jobs = await jobStore.getBy("status.type", { value: "waiting" }); + const userJobs = jobs.filter((j) => j.value.from.id === ctx.from?.id); + for (const job of userJobs) await job.delete(); + await ctx.reply(`Cancelled ${userJobs.length} jobs`); +} diff --git a/bot/mod.ts b/bot/mod.ts index ad7dee6..08ba4c0 100644 --- a/bot/mod.ts +++ b/bot/mod.ts @@ -5,6 +5,7 @@ import { queueCommand } from "./queueCommand.ts"; import { txt2imgCommand, txt2imgQuestion } from "./txt2imgCommand.ts"; import { pnginfoCommand, pnginfoQuestion } from "./pnginfoCommand.ts"; import { img2imgCommand, img2imgQuestion } from "./img2imgCommand.ts"; +import { cancelCommand } from "./cancelCommand.ts"; export const logger = () => Log.getLogger(); @@ -98,10 +99,11 @@ bot.api.setMyDescription( "Send /txt2img to generate an image.", ); bot.api.setMyCommands([ - { command: "txt2img", description: "Generate an image from text" }, - { command: "img2img", description: "Generate an image based on another image" }, + { command: "txt2img", description: "Generate image from text" }, + { command: "img2img", description: "Generate image from image" }, { command: "pnginfo", description: "Show generation parameters of an image" }, { command: "queue", description: "Show the current queue" }, + { command: "cancel", description: "Cancel all your requests" }, ]); bot.command("start", (ctx) => ctx.reply("Hello! Use the /txt2img command to generate an image")); @@ -117,6 +119,8 @@ bot.use(pnginfoQuestion.middleware()); bot.command("queue", queueCommand); +bot.command("cancel", cancelCommand); + bot.command("pause", (ctx) => { if (!ctx.from?.username) return; const config = ctx.session.global;