-
-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f9cdb87
commit e346a5e
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |