diff --git a/README.md b/README.md index 2c7bdf3..5133a43 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,14 @@ Long-term memory commands: /forget_memories ``` +## Images + +Generate and send an image using Pollinations: + +```text +/image a sad robot drinking coffee in Zagreb, noir style +``` + 4. Start the bot: ```bash diff --git a/src/bot.js b/src/bot.js index a9f63e8..1a80cf0 100644 --- a/src/bot.js +++ b/src/bot.js @@ -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;