Rework ai image gen animals

This commit is contained in:
Aslan 2025-12-26 04:59:35 +01:00
parent 4819805b3c
commit c41bae15a6
2 changed files with 58 additions and 69 deletions

View file

@ -3,6 +3,7 @@ import type { ICallbackStore } from "../types.js";
import { config } from "../../config.js";
import { getImageNanoBanana, getTextGemini } from "../../services/ai/ai.js";
import type { IAnimal } from "./types.js";
import { animals } from "./animals.js";
let client: MatrixClient;
@ -17,76 +18,14 @@ const registerModuleAI = (
callbackFunc: onAI,
});
callbackStore.messageCallbacks.push({
startConditions: [
`satek when `,
`satek ked `,
`gabor when `,
`gabor ked `,
`martin when `,
`martin ked `,
`madys when `,
`madys ked `,
`mandak when `,
`mandak ked `,
`mando when `,
`mando ked `,
`mandik when `,
`mandik ked `,
`madik when `,
`madik ked `,
`janys when `,
`janys ked `,
`jano when `,
`jano ked `,
],
startConditions: animals
.map((animal) => `${animal.name} when`)
.concat(animals.map((animal) => `${animal.name} ked`)),
callbackFunc: onImageGen,
});
};
const getAnimal = (name: string): IAnimal | undefined => {
const animals: IAnimal[] = [
{
name: "satek",
animal: "black cat",
},
{
name: "gabor",
animal: "hedgehog",
},
{
name: "martin",
animal: "hedgehog",
},
{
name: "madys",
animal: "beaver",
},
{
name: "mandak",
animal: "beaver",
},
{
name: "mando",
animal: "beaver",
},
{
name: "mandik",
animal: "beaver",
},
{
name: "madik",
animal: "beaver",
},
{
name: "janys",
animal: "lion",
},
{
name: "jano",
animal: "lion",
},
];
const foundAnimals = animals
.map((animal) => {
if (name.includes(animal.name)) {
@ -108,18 +47,22 @@ const onAI = async (text: string, roomId: string) => {
};
const onImageGen = async (text: string, roomId: string) => {
const animal = getAnimal(text.trim().split(/\s+/)[0] ?? "");
if (!animal) {
const firstAnimal = getAnimal(text.trim().split(/\s+/)[0] ?? "");
if (!firstAnimal) {
return;
}
const textMod = text.replace(animal.name, animal.animal);
let textMod = text;
animals.forEach((animal) => {
textMod = textMod.replaceAll(animal.name, animal.animal);
});
const buffer = await getImageNanoBanana(textMod.trim());
if (!buffer || buffer.length < 10) {
return;
}
const imageName = `photo-${animal.name}.png`;
const imageName = `photo-${firstAnimal.name}.png`;
const uploadResult = await client.uploadContent(buffer, {
type: "image/png",

46
src/modules/ai/animals.ts Normal file
View file

@ -0,0 +1,46 @@
import type { IAnimal } from "./types.js";
const animals: IAnimal[] = [
{
name: "satek",
animal: "black cat",
},
{
name: "gabor",
animal: "hedgehog",
},
{
name: "martin",
animal: "hedgehog",
},
{
name: "madys",
animal: "beaver",
},
{
name: "mandak",
animal: "beaver",
},
{
name: "mando",
animal: "beaver",
},
{
name: "mandik",
animal: "beaver",
},
{
name: "madik",
animal: "beaver",
},
{
name: "janys",
animal: "lion",
},
{
name: "jano",
animal: "lion",
},
];
export { animals };