From 4d69b87b97f740300adf42503d476b800236f0a0 Mon Sep 17 00:00:00 2001 From: pinks Date: Mon, 11 Sep 2023 19:08:12 +0200 Subject: [PATCH] small changes --- bot/queueCommand.ts | 3 +-- bot/txt2imgCommand.ts | 13 ++++++------- utils.ts | 6 +++--- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/bot/queueCommand.ts b/bot/queueCommand.ts index 2eb490c..e02e333 100644 --- a/bot/queueCommand.ts +++ b/bot/queueCommand.ts @@ -15,7 +15,6 @@ export async function queueCommand(ctx: Grammy.CommandContext) { const waitingJobs = await jobStore.getBy("status.type", "waiting") .then((jobs) => jobs.map((job, index) => ({ ...job.value, place: index + 1 }))); const jobs = [...processingJobs, ...waitingJobs]; - const config = ctx.session.global; const { bold } = GrammyParseMode; return fmt([ "Current queue:\n", @@ -40,7 +39,7 @@ export async function queueCommand(ctx: Grammy.CommandContext) { ]) : ["Queue is empty.\n"], "\nActive workers:\n", - ...config.workers.flatMap((worker) => [ + ...ctx.session.global.workers.flatMap((worker) => [ runningWorkers.has(worker.name) ? "✅ " : "☠️ ", fmt`${bold(worker.name)} `, `(max ${(worker.maxResolution / 1000000).toFixed(1)} Mpx) `, diff --git a/bot/txt2imgCommand.ts b/bot/txt2imgCommand.ts index 08c393d..b405f5f 100644 --- a/bot/txt2imgCommand.ts +++ b/bot/txt2imgCommand.ts @@ -22,24 +22,23 @@ async function txt2img(ctx: Context, match: string, includeRepliedTo: boolean): return; } - const config = ctx.session.global; - if (config.pausedReason != null) { - await ctx.reply(`I'm paused: ${config.pausedReason || "No reason given"}`); + if (ctx.session.global.pausedReason != null) { + await ctx.reply(`I'm paused: ${ctx.session.global.pausedReason || "No reason given"}`); return; } const jobs = await jobStore.getBy("status.type", "waiting"); - if (jobs.length >= config.maxJobs) { + if (jobs.length >= ctx.session.global.maxJobs) { await ctx.reply( - `The queue is full. Try again later. (Max queue size: ${config.maxJobs})`, + `The queue is full. Try again later. (Max queue size: ${ctx.session.global.maxJobs})`, ); return; } const userJobs = jobs.filter((job) => job.value.request.from.id === ctx.message?.from?.id); - if (userJobs.length >= config.maxUserJobs) { + if (userJobs.length >= ctx.session.global.maxUserJobs) { await ctx.reply( - `You already have ${config.maxUserJobs} jobs in queue. Try again later.`, + `You already have ${ctx.session.global.maxUserJobs} jobs in queue. Try again later.`, ); return; } diff --git a/utils.ts b/utils.ts index 736b793..5fe1fae 100644 --- a/utils.ts +++ b/utils.ts @@ -105,7 +105,7 @@ const languageToFlagMap: Record = { "lb": "🇱🇺", // Luxembourgish - Luxembourg }; -export function getFlagEmoji(countryCode?: string): string | undefined { - if (!countryCode) return; - return languageToFlagMap[countryCode]; +export function getFlagEmoji(languageCode?: string): string | undefined { + if (!languageCode) return; + return languageToFlagMap[languageCode]; }