diff --git a/plugins/ai-toon.js b/plugins/ai-toon.js new file mode 100644 index 00000000..f52ff9c7 --- /dev/null +++ b/plugins/ai-toon.js @@ -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} \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 ']; +handler.tags = ['ai']; +handler.command = ['toonai', 'toonimage', 'toon']; + +export default handler;