Add image generation command
This commit is contained in:
parent
09ead526b4
commit
605c135b08
2 changed files with 27 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
19
src/bot.js
19
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;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue