From 07fc0c71f2dbea209235679e7849a344c0101d62 Mon Sep 17 00:00:00 2001 From: nameless Date: Sat, 14 Oct 2023 10:57:46 +0000 Subject: [PATCH] feat: parse seed on new txt2img request (#20) Reviewed-on: https://git.foxo.me/pinks/eris/pulls/20 Co-authored-by: nameless Co-committed-by: nameless --- bot/parsePngInfo.ts | 11 +++++++++-- bot/txt2imgCommand.ts | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/bot/parsePngInfo.ts b/bot/parsePngInfo.ts index dfd693b..45ada41 100644 --- a/bot/parsePngInfo.ts +++ b/bot/parsePngInfo.ts @@ -25,7 +25,7 @@ interface PngInfoExtra extends PngInfo { upscale?: number; } -export function parsePngInfo(pngInfo: string, baseParams?: Partial): Partial { +export function parsePngInfo(pngInfo: string, baseParams?: Partial, shouldParseSeed?: boolean): Partial { const tags = pngInfo.split(/[,;]+|\.+\s|\n/u); let part: "prompt" | "negative_prompt" | "params" = "prompt"; const params: Partial = {}; @@ -99,7 +99,14 @@ export function parsePngInfo(pngInfo: string, baseParams?: Partial): Pa params.denoising_strength = denoisingStrength; break; } - case "seed": + case "seed": { + part = "params"; + if (shouldParseSeed) { + const seed = Number(value.trim()); + params.seed = seed; + break; + } + } case "model": case "modelhash": case "modelname": diff --git a/bot/txt2imgCommand.ts b/bot/txt2imgCommand.ts index e63fb0a..0e087cb 100644 --- a/bot/txt2imgCommand.ts +++ b/bot/txt2imgCommand.ts @@ -64,7 +64,7 @@ async function txt2img(ctx: ErisContext, match: string, includeRepliedTo: boolea params = parsePngInfo(repliedToText, params); } - params = parsePngInfo(match, params); + params = parsePngInfo(match, params, true); if (!params.prompt) { await ctx.reply(