Skip to content

Commit

Permalink
Prevent unexepcted Errors, and also config a Good handler for Loras A…
Browse files Browse the repository at this point in the history
…uto-complete
  • Loading branch information
exatombe committed Jan 5, 2024
1 parent 24ee2f0 commit 93f41a4
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 45 deletions.
110 changes: 77 additions & 33 deletions src/bot/commands/ai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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((_) => {});
});
}
}
2 changes: 1 addition & 1 deletion src/bot/commands/ai/advanced/imagine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.__(
Expand Down
28 changes: 17 additions & 11 deletions src/bot/commands/ai/imagine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -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.__(
Expand Down

0 comments on commit 93f41a4

Please sign in to comment.