const axios = require("axios"); const fs = require("fs"); const path = require("path"); const baseApiUrl = async () => { const base = await axios.get( "https://raw.githubusercontent.com/mahmudx7/HINATA/main/baseApiUrl.json" ); return base.data.mahmud; }; /** * @author MahMUD * @author: do not delete it */ module.exports = { config: { name: "tokai", aliases: ["toqai"], version: "1.7", author: "MahMUD", role: 0, category: "fun", cooldown: 10, guide: "[mention/reply/UID]", }, onStart: async function({ api, event, args }) { const obfuscatedAuthor = String.fromCharCode(77, 97, 104, 77, 85, 68); if (module.exports.config.author !== obfuscatedAuthor) { return api.sendMessage( "You are not authorized to change the author name.\n", event.threadID, event.messageID ); } const { senderID, mentions, threadID, messageID, messageReply } = event; let id; if (Object.keys(mentions).length > 0) { id = Object.keys(mentions)[0]; } else if (messageReply) { id = messageReply.senderID; } else if (args[0]) { id = args[0]; } else { return api.sendMessage( "❌ Mention, reply, or give UID to make tokai someone", threadID, messageID ); } try { const apiUrl = await baseApiUrl(); const url = `${apiUrl}/api/tokai?user=${id}`; const response = await axios.get(url, { responseType: "arraybuffer" }); const filePath = path.join(__dirname, `tokai_${id}.png`); fs.writeFileSync(filePath, response.data); api.sendMessage( { attachment: fs.createReadStream(filePath), body: "Here's your tokai image 🐸" }, threadID, () => fs.unlinkSync(filePath), messageID ); } catch (err) { api.sendMessage(`🥹error, contact MahMUD.`, threadID, messageID); } } };