Skip to content

Commit

Permalink
[ Jessi-md 4.8.4 ⏱️ ]
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaweeshachamodx authored Jan 28, 2024
1 parent f9cdb87 commit e346a5e
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions plugins/ai-toon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import fetch from 'node-fetch';

let handler = async (m, { conn, text, args, usedPrefix, command }) => {
if (!text || !args[0]) throw `> Usage: ${usedPrefix + command} <aversion> <text>\n\nAvailable verions:\nai\nv1\nv2\nv3\nv4\nv5\nv6\n\nExample: ${usedPrefix + command} v4 cute girl in pink dress`;

const apiVersion = args[0].toLowerCase();
const validVersions = ['ai', 'v1', 'v2', 'v3', 'v4', 'v5', 'v6'];

if (!validVersions.includes(apiVersion)) {
throw `> Invalid version. Supported versions: ${validVersions.join(', ')}`;
m.react('🤐');
}

const promptText = args.slice(1).join(' ');

try {
let mess = await m.reply('> Generating toon image...');
m.react('🖌');

const endpoint = `https://aemt.me/${apiVersion}/text2img?text=${encodeURIComponent(promptText)}`;
const response = await fetch(endpoint);

if (response.ok) {
const imageBuffer = await response.arrayBuffer();

//await m.reply({ key: mess.key, text: '> Here generated image...' });
await conn.sendFile(m.chat, Buffer.from(imageBuffer), 'toon_image.png', null, m);
await m.react('😊');
} else {
throw '> Toon image generation failed';
m.react('😕');
}
} catch {
throw '> Oops! Something went wrong while generating toon image. Please try again later.';
m.react('😕');
}
};

handler.help = ['toonai <version> <text>'];
handler.tags = ['ai'];
handler.command = ['toonai', 'toonimage', 'toon'];

export default handler;

0 comments on commit e346a5e

Please sign in to comment.