// code from goatstore // api: https://store.agi.bd const axios = require("axios"); module.exports = { config: { name: "math", aliases: ["mathgame", "quiz"], version: "1.7", author: "Redwan", longDescription: { en: "🧠 š™š™š™žš™£š™  š™®š™¤š™Ŗ'š™§š™š š™Øš™¢š™–š™§š™©? š™š™§š™® š™©š™š™žš™Ø š™¢š™–š™©š™ š™˜š™š™–š™”š™”š™šš™£š™œš™š! šŸ†" }, category: "šŸŽ® š™‚š™–š™¢š™šš™Ø", guide: { en: "⚔ š™š™®š™„š™š: **{p}{n}** | š™Žš™šš™© š™¢š™¤š™™š™š: **{p}{n} š™Øš™šš™© **" }, }, userSettings: new Map(), onStart: async function ({ message, event, args }) { const userID = event.senderID; if (!this.userSettings.has(userID)) { this.userSettings.set(userID, { difficulty: "normal", type: "text" }); } let userSetting = this.userSettings.get(userID); if (args.length === 3 && args[0] === "set") { const difficulty = args[1].toLowerCase(); const type = args[2].toLowerCase(); const validDifficulties = ["easy", "normal", "hard"]; const validTypes = ["text", "number"]; if (!validDifficulties.includes(difficulty) || !validTypes.includes(type)) { return message.reply( `āš ļø š™„š™£š™«š™–š™”š™žš™™ š™˜š™š™¤š™žš™˜š™š! āŒ\nšŸ“Œ š˜æš™žš™›š™›š™žš™˜š™Ŗš™”š™©š™®: **š™šš™–š™Øš™®, š™£š™¤š™§š™¢š™–š™”, š™š™–š™§š™™**\nšŸ“Œ š™š™®š™„š™š: **š™©š™šš™­š™©, š™£š™Ŗš™¢š™—š™šš™§**` ); } userSetting.difficulty = difficulty; userSetting.type = type; this.userSettings.set(userID, userSetting); return message.reply(`āœ… š™Žš™šš™©š™©š™žš™£š™œš™Ø š™š™„š™™š™–š™©š™šš™™!\nšŸŽÆ š˜æš™žš™›š™›š™žš™˜š™Ŗš™”š™©š™®: **${difficulty}**\nšŸŽÆ š™š™®š™„š™š: **${type}**`); } try { const { difficulty, type } = userSetting; const apiUrl = `https://global-redwans-apis.onrender.com/api/math?difficulty=${difficulty}&type=${type}`; const response = await axios.get(apiUrl); const data = response.data; if (!data.question || !data.options) { return message.reply("āŒ š™š™–š™žš™”š™šš™™ š™©š™¤ š™œš™šš™£š™šš™§š™–š™©š™š š™– š™¦š™Ŗš™šš™Øš™©š™žš™¤š™£!"); } const { question, options, correct_answer: correctAnswer } = data; const optionKeys = Object.keys(options); let optionsText = optionKeys.map((key, index) => `${index + 1}. ${options[key]}`).join("\n"); let timeoutDuration = difficulty === "easy" ? 30000 : difficulty === "normal" ? 35000 : 40000; message.reply( `šŸŽÆ š™ˆš˜¼š™š™ƒ š™‚š˜¼š™ˆš™€ 🧮\n\nšŸ“¢ **š™Œš™Ŗš™šš™Øš™©š™žš™¤š™£:** ${question}\n\n${optionsText}\n\n✨ š™š™šš™„š™”š™® š™¬š™žš™©š™ (šŸ­,šŸ®,šŸÆ,šŸ°) š™©š™¤ š™–š™£š™Øš™¬š™šš™§! (ā³ **š™š™žš™¢š™š: ${timeoutDuration / 1000} š™Øš™šš™˜š™¤š™£š™™š™Ø**)`, (err, info) => { if (!err) { const timeout = setTimeout(() => { if (global.GoatBot.onReply.has(info.messageID)) { message.unsend(info.messageID); global.GoatBot.onReply.delete(info.messageID); message.reply("ā³ **š™š™žš™¢š™š'š™Ø š™Ŗš™„!** āŒ š™”š™¤š™Ŗ š™”š™¤š™Øš™š!"); } }, timeoutDuration); global.GoatBot.onReply.set(info.messageID, { commandName: this.config.name, messageID: info.messageID, author: event.senderID, options: options, correctAnswer: correctAnswer, timeout: timeout, }); } } ); } catch (error) { console.error("Error fetching the math problem:", error.message); message.reply("āŒ š™Šš™¤š™„š™Ø! š™Žš™¤š™¢š™šš™©š™š™žš™£š™œ š™¬š™šš™£š™© š™¬š™§š™¤š™£š™œ!"); } }, onReply: async function ({ message, event }) { try { const userAnswer = event.body.trim(); const replyData = global.GoatBot.onReply.get(event.messageReply.messageID); if (!replyData || replyData.author !== event.senderID) return; const { options, correctAnswer } = replyData; const optionKeys = Object.keys(options); const userSelectedOption = optionKeys[parseInt(userAnswer) - 1]; message.unsend(event.messageReply.messageID); if (!userSelectedOption || options[userSelectedOption] === undefined) { return message.reply("āš ļø **š™„š™£š™«š™–š™”š™žš™™ š˜¾š™š™¤š™žš™˜š™š!** āŒ š™‹š™”š™šš™–š™Øš™š š™Øš™šš™”š™šš™˜š™© š™– š™£š™Ŗš™¢š™—š™šš™§ (šŸ­-šŸ°)."); } const userSelectedAnswer = options[userSelectedOption]; if (parseFloat(userSelectedAnswer) === parseFloat(correctAnswer)) { message.reply("šŸŽ‰ **š˜¾š™Šš™š™š™€š˜¾š™!** šŸ† š™”š™¤š™Ŗ š™¬š™žš™£!"); } else { message.reply("āŒ **š™’š™§š™¤š™£š™œ!** š˜½š™šš™©š™©š™šš™§ š™”š™Ŗš™˜š™  š™£š™šš™­š™© š™©š™žš™¢š™š."); } global.GoatBot.onReply.delete(event.messageReply.messageID); } catch (error) { console.error("Error checking answer:", error.message); message.reply("āš ļø **š™€š™§š™§š™¤š™§!**"); } }, };