From 93f41a4e40a4bd20c3c5a3b4f68cd64929d29aa3 Mon Sep 17 00:00:00 2001 From: garder500 Date: Fri, 5 Jan 2024 21:16:43 +0100 Subject: [PATCH] Prevent unexepcted Errors, and also config a Good handler for Loras Auto-complete --- src/bot/commands/ai.ts | 110 +++++++++++++++++------- src/bot/commands/ai/advanced/imagine.ts | 2 +- src/bot/commands/ai/imagine.ts | 28 +++--- 3 files changed, 95 insertions(+), 45 deletions(-) diff --git a/src/bot/commands/ai.ts b/src/bot/commands/ai.ts index 9d347d6..2807af2 100644 --- a/src/bot/commands/ai.ts +++ b/src/bot/commands/ai.ts @@ -55,6 +55,30 @@ const commandData = new SlashCommandBuilder() fr: "loras", }) .setAutocomplete(true), + ).addStringOption((option) => + option.setName("loras_2").setDescription("Loras to use").setRequired(false).setDescriptionLocalizations({ + fr: "Loras à utiliser", + }).setNameLocalizations({ + fr: "second_loras", + }).setAutocomplete(true), + ).addStringOption((option) => + option.setName("loras_3").setDescription("Loras to use").setRequired(false).setDescriptionLocalizations({ + fr: "Loras à utiliser", + }).setNameLocalizations({ + fr: "third_loras", + }).setAutocomplete(true), + ).addStringOption((option) => + option.setName("loras_4").setDescription("Loras to use").setRequired(false).setDescriptionLocalizations({ + fr: "Loras à utiliser", + }).setNameLocalizations({ + fr: "fourth_loras", + }).setAutocomplete(true), + ).addStringOption((option) => + option.setName("loras_5").setDescription("Loras to use").setRequired(false).setDescriptionLocalizations({ + fr: "Loras à utiliser", + }).setNameLocalizations({ + fr: "fifth_loras", + }).setAutocomplete(true), ) .addBooleanOption((option) => option @@ -503,41 +527,61 @@ export class IaCommand extends CommandsBase { }); break; case "loras": - if (!isNaN(Number(autocomplete.value))) { - this.client.getLorasModel(autocomplete.value).then((Loras) => { - if (Loras) { - interaction.respond([ - { - name: Loras.name, - value: String(Loras.id), - } - ]) - } - }); - } else { - this.client.getLorasModels({ - name: autocomplete.value, - limit: 5 - }).then((Loras) => { - if(!Loras) return interaction.respond([]); - console.log(Loras.items); - interaction - .respond( - Loras.items.map((model) => { - return { - name: model.name.substring(0, 60), - value: String(model.id), - }; - }), - ) - .catch((err) => { - console.log(err); - // ignore Too Much Time passed - }); - }); - } + lorasLookup(autocomplete.value, interaction, this.client); + break; + case "loras_2": + lorasLookup(autocomplete.value, interaction, this.client); + break; + case "loras_3": + lorasLookup(autocomplete.value, interaction, this.client); + break; + case "loras_4": + lorasLookup(autocomplete.value, interaction, this.client); + break; + case "loras_5": + lorasLookup(autocomplete.value, interaction, this.client); break; } } } } + + +function lorasLookup(value: string, interaction: AutocompleteInteraction, client: Bot) { + if (!isNaN(Number(value))) { + client.getLorasModel(value).then((Loras) => { + interaction.respond([ + { + name: Loras.name, + value: String(Loras.id), + } + ]).catch((_) => {}); + }).catch((err) => { + interaction.respond([{ + name:"No loras found", + value: "0" + }]).catch((_) => {}); + }); + } else { + client.getLorasModels({ + name: value, + limit: 5 + }).then((Loras) => { + interaction + .respond( + Loras.items.map((model) => { + return { + name: model.name, + value: String(model.id), + }; + }), + ) + .catch((_) => {}); + }).catch((err) => { + interaction.respond([{ + name:"No loras found", + value: "0" + }]).catch((_) => {}); + }); + } +} \ No newline at end of file diff --git a/src/bot/commands/ai/advanced/imagine.ts b/src/bot/commands/ai/advanced/imagine.ts index 09c90cc..e499f72 100644 --- a/src/bot/commands/ai/advanced/imagine.ts +++ b/src/bot/commands/ai/advanced/imagine.ts @@ -265,7 +265,7 @@ export default async function AdvancedImagine( ((Date.now() + wait_time * 1000) / 1000).toString(), ), ), - ); + ) + "\n"; } if (stat.kudos && stat.kudos > 0) { processed += bt.__( diff --git a/src/bot/commands/ai/imagine.ts b/src/bot/commands/ai/imagine.ts index da2ce4a..49d4108 100644 --- a/src/bot/commands/ai/imagine.ts +++ b/src/bot/commands/ai/imagine.ts @@ -75,6 +75,10 @@ export default async function Imagine( "deformed, blurry,[bad anatomy], disfigured, poorly drawn face, [[[mutation]]], mutated, [[[extra arms]]], extra legs, ugly, horror, out of focus, depth of field, focal blur, bad quality, double body, [[double torso]], equine, bovine,[[feral]], [duo], [[canine]], creepy fingers, extra fingers, bad breasts, bad butt, split breasts, split butt, Blurry textures, blurry everything, creepy arms, bad arm anatomy, bad leg anatomy, bad finger anatomy, poor connection of the body with clothing and other things, poor quality character, poor quality body, Bad clothes quality, bad underwear, bad ears, poor eyes quality, poor quality of the background, poor facial quality, text."; let nsfw = options.getBoolean("nsfw") || false; let loras = options.getString("loras") || null; + let loras2 = options.getString("loras_2") || null; + let loras3 = options.getString("loras_3") || null; + let loras4 = options.getString("loras_4") || null; + let loras5 = options.getString("loras_5") || null; let preprompt = options.getBoolean("preprompt") || false; if (image) { let textChannel = @@ -106,12 +110,14 @@ export default async function Imagine( nsfw: nsfwchannel ? (nsfw ? true : false) : false, shared: true, }; - - if (loras) { + let lorasList = [loras, loras2, loras3, loras4, loras5].filter((loras) => { + return loras !== null; + }); + if (lorasList.length > 0) { // if preprompt is selected, we get a random model, and a random image from this model to use as prompt if (preprompt) { try { - let lorasDatas = await command.client.getLorasModel(loras); + let lorasDatas = await command.client.getLorasModel(lorasList[0]); let randomModelVersion = lorasDatas.modelVersions[ Math.floor(Math.random() * lorasDatas.modelVersions.length) @@ -132,14 +138,14 @@ export default async function Imagine( } } - prompt.params.loras = [ - { + prompt.params.loras = lorasList.map((loras, index) => { + return { name: loras, - model: 1, - clip: 1, - inject_trigger: "any" - }, - ]; + model: index, + clip: index+1, + inject_trigger: "any", + }; + }); } if (model.toLowerCase().includes("sdxl")) { prompt.params.hires_fix = false; @@ -278,7 +284,7 @@ export default async function Imagine( ((Date.now() + wait_time * 1000) / 1000).toString(), ), ), - ); + ) + "\n"; } if (stat.kudos && stat.kudos > 0) { processed += bt.__(