Add image generation command

This commit is contained in:
hbrain 2026-05-22 07:52:37 +00:00
parent 09ead526b4
commit 605c135b08
2 changed files with 27 additions and 0 deletions

View file

@ -184,6 +184,7 @@ bot.command('help', (ctx) => {
ctx.reply(`Just send me a text message. I remember recent conversation using SQLite.
Commands:
/image prompt - generate and send an image
/remember key = value - save a permanent fact
/memories - show permanent facts
/forget_memory key - delete one permanent fact
@ -232,6 +233,24 @@ bot.command('forget', (ctx) => {
ctx.reply('Recent chat history cleared for this chat. Long-term memories were kept.');
});
bot.command('image', async (ctx) => {
const prompt = ctx.message.text.replace(/^\/image(@\w+)?\s*/i, '').trim();
if (!prompt) {
await ctx.reply('Use: /image prompt\nExample: /image a sad robot drinking coffee in Zagreb, noir style');
return;
}
try {
await ctx.sendChatAction('upload_photo');
const imageUrl = `https://image.pollinations.ai/prompt/${encodeURIComponent(prompt)}?width=1024&height=1024&nologo=true&safe=true`;
await ctx.replyWithPhoto({ url: imageUrl }, { caption: prompt.slice(0, 1024) });
} catch (error) {
console.error('Failed to generate image:', error);
await ctx.reply('Sorry, image generation failed. Try a different prompt.');
}
});
bot.on('text', async (ctx) => {
const text = ctx.message.text;