From e346a5ecb42bb75d42b252c9f7b8a70f45d6a3fa Mon Sep 17 00:00:00 2001 From: KaweeX <88151250+Kaweeshachamodx@users.noreply.github.com> Date: Sun, 28 Jan 2024 10:58:58 +0530 Subject: [PATCH] =?UTF-8?q?[=20Jessi-md=204.8.4=20=E2=8F=B1=EF=B8=8F=20]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/ai-toon.js | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 plugins/ai-toon.js 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;