Skip to content

Commit 93f41a4

Browse files
committed
Prevent unexepcted Errors, and also config a Good handler for Loras Auto-complete
1 parent 24ee2f0 commit 93f41a4

File tree

3 files changed

+95
-45
lines changed

3 files changed

+95
-45
lines changed

src/bot/commands/ai.ts

Lines changed: 77 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,30 @@ const commandData = new SlashCommandBuilder()
5555
fr: "loras",
5656
})
5757
.setAutocomplete(true),
58+
).addStringOption((option) =>
59+
option.setName("loras_2").setDescription("Loras to use").setRequired(false).setDescriptionLocalizations({
60+
fr: "Loras à utiliser",
61+
}).setNameLocalizations({
62+
fr: "second_loras",
63+
}).setAutocomplete(true),
64+
).addStringOption((option) =>
65+
option.setName("loras_3").setDescription("Loras to use").setRequired(false).setDescriptionLocalizations({
66+
fr: "Loras à utiliser",
67+
}).setNameLocalizations({
68+
fr: "third_loras",
69+
}).setAutocomplete(true),
70+
).addStringOption((option) =>
71+
option.setName("loras_4").setDescription("Loras to use").setRequired(false).setDescriptionLocalizations({
72+
fr: "Loras à utiliser",
73+
}).setNameLocalizations({
74+
fr: "fourth_loras",
75+
}).setAutocomplete(true),
76+
).addStringOption((option) =>
77+
option.setName("loras_5").setDescription("Loras to use").setRequired(false).setDescriptionLocalizations({
78+
fr: "Loras à utiliser",
79+
}).setNameLocalizations({
80+
fr: "fifth_loras",
81+
}).setAutocomplete(true),
5882
)
5983
.addBooleanOption((option) =>
6084
option
@@ -503,41 +527,61 @@ export class IaCommand extends CommandsBase {
503527
});
504528
break;
505529
case "loras":
506-
if (!isNaN(Number(autocomplete.value))) {
507-
this.client.getLorasModel(autocomplete.value).then((Loras) => {
508-
if (Loras) {
509-
interaction.respond([
510-
{
511-
name: Loras.name,
512-
value: String(Loras.id),
513-
}
514-
])
515-
}
516-
});
517-
} else {
518-
this.client.getLorasModels({
519-
name: autocomplete.value,
520-
limit: 5
521-
}).then((Loras) => {
522-
if(!Loras) return interaction.respond([]);
523-
console.log(Loras.items);
524-
interaction
525-
.respond(
526-
Loras.items.map((model) => {
527-
return {
528-
name: model.name.substring(0, 60),
529-
value: String(model.id),
530-
};
531-
}),
532-
)
533-
.catch((err) => {
534-
console.log(err);
535-
// ignore Too Much Time passed
536-
});
537-
});
538-
}
530+
lorasLookup(autocomplete.value, interaction, this.client);
531+
break;
532+
case "loras_2":
533+
lorasLookup(autocomplete.value, interaction, this.client);
534+
break;
535+
case "loras_3":
536+
lorasLookup(autocomplete.value, interaction, this.client);
537+
break;
538+
case "loras_4":
539+
lorasLookup(autocomplete.value, interaction, this.client);
540+
break;
541+
case "loras_5":
542+
lorasLookup(autocomplete.value, interaction, this.client);
539543
break;
540544
}
541545
}
542546
}
543547
}
548+
549+
550+
function lorasLookup(value: string, interaction: AutocompleteInteraction, client: Bot) {
551+
if (!isNaN(Number(value))) {
552+
client.getLorasModel(value).then((Loras) => {
553+
interaction.respond([
554+
{
555+
name: Loras.name,
556+
value: String(Loras.id),
557+
}
558+
]).catch((_) => {});
559+
}).catch((err) => {
560+
interaction.respond([{
561+
name:"No loras found",
562+
value: "0"
563+
}]).catch((_) => {});
564+
});
565+
} else {
566+
client.getLorasModels({
567+
name: value,
568+
limit: 5
569+
}).then((Loras) => {
570+
interaction
571+
.respond(
572+
Loras.items.map((model) => {
573+
return {
574+
name: model.name,
575+
value: String(model.id),
576+
};
577+
}),
578+
)
579+
.catch((_) => {});
580+
}).catch((err) => {
581+
interaction.respond([{
582+
name:"No loras found",
583+
value: "0"
584+
}]).catch((_) => {});
585+
});
586+
}
587+
}

src/bot/commands/ai/advanced/imagine.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ export default async function AdvancedImagine(
265265
((Date.now() + wait_time * 1000) / 1000).toString(),
266266
),
267267
),
268-
);
268+
) + "\n";
269269
}
270270
if (stat.kudos && stat.kudos > 0) {
271271
processed += bt.__(

src/bot/commands/ai/imagine.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ export default async function Imagine(
7575
"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.";
7676
let nsfw = options.getBoolean("nsfw") || false;
7777
let loras = options.getString("loras") || null;
78+
let loras2 = options.getString("loras_2") || null;
79+
let loras3 = options.getString("loras_3") || null;
80+
let loras4 = options.getString("loras_4") || null;
81+
let loras5 = options.getString("loras_5") || null;
7882
let preprompt = options.getBoolean("preprompt") || false;
7983
if (image) {
8084
let textChannel =
@@ -106,12 +110,14 @@ export default async function Imagine(
106110
nsfw: nsfwchannel ? (nsfw ? true : false) : false,
107111
shared: true,
108112
};
109-
110-
if (loras) {
113+
let lorasList = [loras, loras2, loras3, loras4, loras5].filter((loras) => {
114+
return loras !== null;
115+
});
116+
if (lorasList.length > 0) {
111117
// if preprompt is selected, we get a random model, and a random image from this model to use as prompt
112118
if (preprompt) {
113119
try {
114-
let lorasDatas = await command.client.getLorasModel(loras);
120+
let lorasDatas = await command.client.getLorasModel(lorasList[0]);
115121
let randomModelVersion =
116122
lorasDatas.modelVersions[
117123
Math.floor(Math.random() * lorasDatas.modelVersions.length)
@@ -132,14 +138,14 @@ export default async function Imagine(
132138
}
133139
}
134140

135-
prompt.params.loras = [
136-
{
141+
prompt.params.loras = lorasList.map((loras, index) => {
142+
return {
137143
name: loras,
138-
model: 1,
139-
clip: 1,
140-
inject_trigger: "any"
141-
},
142-
];
144+
model: index,
145+
clip: index+1,
146+
inject_trigger: "any",
147+
};
148+
});
143149
}
144150
if (model.toLowerCase().includes("sdxl")) {
145151
prompt.params.hires_fix = false;
@@ -278,7 +284,7 @@ export default async function Imagine(
278284
((Date.now() + wait_time * 1000) / 1000).toString(),
279285
),
280286
),
281-
);
287+
) + "\n";
282288
}
283289
if (stat.kudos && stat.kudos > 0) {
284290
processed += bt.__(

0 commit comments

Comments
 (0)