MCPcopy Create free account
hub / github.com/GlobalTechInfo/MEGA-MDX / handler

Function handler

plugins/imagine-diffusion.ts:44–76  ·  view source on GitHub ↗
(sock: any, message: any, args: string[], context: BotContext)

Source from the content-addressed store, hash-verified

42 usage: '.diffusion <prompt>',
43
44 async handler(sock: any, message: any, args: string[], context: BotContext) {
45 const chatId = context.chatId || message.key.remoteJid;
46 const imagePrompt = args.join(' ').trim();
47
48 if (!imagePrompt) {
49 return sock.sendMessage(
50 chatId,
51 { text: '🎨 *AI Image Generator*\n\nUsage: `.diffusion <prompt>`\nExample: `.diffusion a beautiful sunset over mountains`' },
52 { quoted: message }
53 );
54 }
55
56 await sock.sendMessage(chatId, { react: { text: '🎨', key: message.key } });
57 await sock.sendMessage(chatId, { text: '🎨 Generating your image... Please wait.' }, { quoted: message });
58
59 try {
60 const enhanced = enhancePrompt(imagePrompt);
61 const imageBuffer = await generateImage(enhanced);
62
63 await sock.sendMessage(chatId, {
64 image: imageBuffer,
65 caption: `🎨 *Generated Image*\n📝 Prompt: _${imagePrompt}_`
66 }, { quoted: message });
67
68 } catch (error: any) {
69 console.error('Imagine error:', error.message);
70 await sock.sendMessage(
71 chatId,
72 { text: '❌ Failed to generate image. Please try again later.' },
73 { quoted: message }
74 );
75 }
76 }
77};

Callers

nothing calls this directly

Calls 2

enhancePromptFunction · 0.70
generateImageFunction · 0.70

Tested by

no test coverage detected