forked from pinks/eris
1
0
Fork 0

main #14

Merged
nameless merged 16 commits from pinks/eris:main into main 2024-01-03 00:41:03 +00:00
1 changed files with 22 additions and 14 deletions
Showing only changes of commit ac63e39373 - Show all commits

View File

@ -6,6 +6,7 @@ import { generationQueue } from "../app/generationQueue.ts";
import { formatUserChat } from "../utils/formatUserChat.ts"; import { formatUserChat } from "../utils/formatUserChat.ts";
import { ErisContext } from "./mod.ts"; import { ErisContext } from "./mod.ts";
import { getPngInfo, parsePngInfo, PngInfo } from "./parsePngInfo.ts"; import { getPngInfo, parsePngInfo, PngInfo } from "./parsePngInfo.ts";
import { adminStore } from "../app/adminStore.ts";
export const txt2imgQuestion = new StatelessQuestion<ErisContext>( export const txt2imgQuestion = new StatelessQuestion<ErisContext>(
"txt2img", "txt2img",
@ -29,6 +30,7 @@ async function txt2img(ctx: ErisContext, match: string, includeRepliedTo: boolea
} }
const config = await getConfig(); const config = await getConfig();
let priority = 0;
if (config.pausedReason != null) { if (config.pausedReason != null) {
await ctx.reply(`I'm paused: ${config.pausedReason || "No reason given"}`, { await ctx.reply(`I'm paused: ${config.pausedReason || "No reason given"}`, {
@ -37,6 +39,11 @@ async function txt2img(ctx: ErisContext, match: string, includeRepliedTo: boolea
return; return;
} }
const [admin] = await adminStore.getBy("tgUserId", { value: ctx.from.id });
if (admin) {
priority = 1;
} else {
const jobs = await generationQueue.getAllJobs(); const jobs = await generationQueue.getAllJobs();
if (jobs.length >= config.maxJobs) { if (jobs.length >= config.maxJobs) {
await ctx.reply(`The queue is full. Try again later. (Max queue size: ${config.maxJobs})`, { await ctx.reply(`The queue is full. Try again later. (Max queue size: ${config.maxJobs})`, {
@ -47,11 +54,12 @@ async function txt2img(ctx: ErisContext, match: string, includeRepliedTo: boolea
const userJobs = jobs.filter((job) => job.state.from.id === ctx.message?.from?.id); const userJobs = jobs.filter((job) => job.state.from.id === ctx.message?.from?.id);
if (userJobs.length >= config.maxUserJobs) { if (userJobs.length >= config.maxUserJobs) {
await ctx.reply(`You already have ${userJobs.length} jobs in queue. Try again later.`, { await ctx.reply(`You already have ${userJobs.length} jobs in the queue. Try again later.`, {
reply_to_message_id: ctx.message?.message_id, reply_to_message_id: ctx.message?.message_id,
}); });
return; return;
} }
}
let params: Partial<PngInfo> = {}; let params: Partial<PngInfo> = {};
@ -103,7 +111,7 @@ async function txt2img(ctx: ErisContext, match: string, includeRepliedTo: boolea
chat: ctx.message.chat, chat: ctx.message.chat,
requestMessage: ctx.message, requestMessage: ctx.message,
replyMessage: replyMessage, replyMessage: replyMessage,
}, { retryCount: 3, retryDelayMs: 10_000 }); }, { retryCount: 3, retryDelayMs: 10_000, priority: priority });
debug(`Generation (txt2img) enqueued for ${formatUserChat(ctx.message)}`); debug(`Generation (txt2img) enqueued for ${formatUserChat(ctx.message)}`);
} }