forked from pinks/eris
1
0
Fork 0

feat: add cancel command

This commit is contained in:
pinks 2023-09-18 17:51:19 +02:00
parent 3f27b4470b
commit 3444fb01d0
2 changed files with 15 additions and 2 deletions

9
bot/cancelCommand.ts Normal file
View File

@ -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`);
}

View File

@ -5,6 +5,7 @@ import { queueCommand } from "./queueCommand.ts";
import { txt2imgCommand, txt2imgQuestion } from "./txt2imgCommand.ts"; import { txt2imgCommand, txt2imgQuestion } from "./txt2imgCommand.ts";
import { pnginfoCommand, pnginfoQuestion } from "./pnginfoCommand.ts"; import { pnginfoCommand, pnginfoQuestion } from "./pnginfoCommand.ts";
import { img2imgCommand, img2imgQuestion } from "./img2imgCommand.ts"; import { img2imgCommand, img2imgQuestion } from "./img2imgCommand.ts";
import { cancelCommand } from "./cancelCommand.ts";
export const logger = () => Log.getLogger(); export const logger = () => Log.getLogger();
@ -98,10 +99,11 @@ bot.api.setMyDescription(
"Send /txt2img to generate an image.", "Send /txt2img to generate an image.",
); );
bot.api.setMyCommands([ bot.api.setMyCommands([
{ command: "txt2img", description: "Generate an image from text" }, { command: "txt2img", description: "Generate image from text" },
{ command: "img2img", description: "Generate an image based on another image" }, { command: "img2img", description: "Generate image from image" },
{ command: "pnginfo", description: "Show generation parameters of an image" }, { command: "pnginfo", description: "Show generation parameters of an image" },
{ command: "queue", description: "Show the current queue" }, { 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")); 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("queue", queueCommand);
bot.command("cancel", cancelCommand);
bot.command("pause", (ctx) => { bot.command("pause", (ctx) => {
if (!ctx.from?.username) return; if (!ctx.from?.username) return;
const config = ctx.session.global; const config = ctx.session.global;