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