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

Function handler

plugins/animes.js:57–85  ·  view source on GitHub ↗
(sock, message, args, context)

Source from the content-addressed store, hash-verified

55 description: 'Send random anime images',
56 usage: '.animes <anime_name>',
57 async handler(sock, message, args, context) {
58 const chatId = context.chatId || message.key.remoteJid;
59 const input = args[0] ? args[0] : '';
60 const typeLower = input.toLowerCase();
61 if (!input || !supportedAnimes.includes(typeLower)) {
62 const replyText = input && !supportedAnimes.includes(typeLower)
63 ? `Unsupported anime: ${typeLower}\n\n`
64 : '';
65 return await sock.sendMessage(chatId, { text: replyText + animuMenu }, { quoted: message });
66 }
67 try {
68 const apiUrl = `https://raw.githubusercontent.com/Guru322/api/Guru/BOT-JSON/anime-${typeLower}.json`;
69 const res = await axios.get(apiUrl, { timeout: 15000, validateStatus: s => s < 500 });
70 const images = res.data;
71 if (!Array.isArray(images) || images.length === 0)
72 throw new Error('No images found');
73 const randomImages = pickRandom(images, Math.min(3, images.length));
74 for (const img of randomImages) {
75 try {
76 const imageData = await axios.get(img, { responseType: 'arraybuffer', timeout: 15000 });
77 await sock.sendMessage(chatId, { image: Buffer.from(imageData.data), caption: `_${typeLower}_` }, { quoted: message });
78 }
79 catch { }
80 }
81 }
82 catch (err) {
83 await sock.sendMessage(chatId, { text: '❌ Failed to fetch anime images. Please try again later.' }, { quoted: message });
84 }
85 }
86};

Callers

nothing calls this directly

Calls 1

pickRandomFunction · 0.70

Tested by

no test coverage detected