// code from goatstore // api: https://store.agi.bd const axios = require("axios"); const API_URL = "https://marufx7.vercel.app/quiz"; const TIMEOUT_MS = 40000; const RESULT_DELETE_MS = 5000; module.exports = { config: { name: "quiz", aliases: ["qz"], version: "1.1.0", author: "𝗠𝗮𝗥𝘂𝗙", role: 0, category: "fun", guide: "{pn} — random quiz question" }, onStart: async function ({ api, event }) { const { threadID, messageID, senderID } = event; try { const response = await axios.get(API_URL, { timeout: 15000 }); const data = response.data; if (!data.ok || !data.id || !data.question || !Array.isArray(data.options) || !data.options.length || !data.answer) { return api.sendMessage( "❌ কুইজ লোড করা যায়নি।", threadID, messageID ); } const labels = ["𝐀", "𝐁", "𝐂", "𝐃", "𝐄", "𝐅"]; const optionLines = data.options.map(function (opt, i) { return "│ " + (labels[i] || String(i + 1)) + ". " + opt; }).join("\n"); const body = "╭─ ❓ 𝐐𝐮𝐞𝐬𝐭𝐢𝐨𝐧\n" + "│ " + data.question + "\n" + "╰\n\n" + "╭─ 📋 𝐎𝐩𝐭𝐢𝐨𝐧𝐬\n" + optionLines + "\n" + "╰\n\n" + "⏳ 𝐓𝐢𝐦𝐞: ৪০ সেকেন্ড\n" + "✍️ অপশনের অক্ষর বা নম্বর দিয়ে রিপ্লাই করুন।"; const sent = await api.sendMessage(body, threadID, messageID); const timeoutId = setTimeout(async function () { const entry = global.GoatBot.onReply.get(sent.messageID); if (!entry) return; global.GoatBot.onReply.delete(sent.messageID); try { const timeoutMsg = await api.sendMessage( "╭─ ⏰ 𝐓𝐈𝐌𝐄 𝐎𝐔𝐓\n" + "│ ❌ সময় শেষ! কুইজ বাতিল হয়েছে।\n" + "│ ✅ সঠিক উত্তর: " + entry.answer + "\n" + "╰", threadID, entry.messageID ); setTimeout(async function () { try { await api.unsendMessage(timeoutMsg.messageID); } catch (_) {} }, RESULT_DELETE_MS); await api.unsendMessage(entry.messageID); } catch (_) {} }, TIMEOUT_MS); global.GoatBot.onReply.set(sent.messageID, { commandName: this.config.name, messageID: sent.messageID, author: senderID, threadID: threadID, options: data.options, answer: data.answer, timeoutId: timeoutId }); } catch (error) { return api.sendMessage( "❌ Quiz API থেকে প্রশ্ন আনতে সমস্যা হয়েছে।", threadID, messageID ); } }, onReply: async function ({ api, event, Reply }) { const { threadID, messageID, senderID, body } = event; if (!global.GoatBot.onReply.has(Reply.messageID)) return; if (senderID !== Reply.author) { return api.sendMessage( "❌ এই কুইজের উত্তর শুধু প্রশ্নদাতা দিতে পারবেন।", threadID, messageID ); } if (!body || !body.trim()) return; const input = body.trim().replace(/[০-৯]/g, function (d) { return String("০১২৩৪৫৬৭৮৯".indexOf(d)); }); const labels = ["A", "B", "C", "D", "E", "F"]; let index = -1; if (/^[1-9]$/.test(input)) { index = Number(input) - 1; } else { index = labels.findIndex(function (label, i) { return label.toLowerCase() === input.toLowerCase() && i < Reply.options.length; }); if (index === -1) { index = Reply.options.findIndex(function (opt) { return String(opt).trim().toLowerCase() === input.toLowerCase(); }); } } if (index < 0 || index >= Reply.options.length) { return api.sendMessage( "❌ ভুল অপশন! 1-" + Reply.options.length + " এর মধ্যে নম্বর অথবা A-F অক্ষর দিন।", threadID, messageID ); } if (Reply.timeoutId) clearTimeout(Reply.timeoutId); global.GoatBot.onReply.delete(Reply.messageID); const selected = Reply.options[index]; const correct = String(selected).trim().toLowerCase() === String(Reply.answer).trim().toLowerCase(); let resultText; if (correct) { resultText = "╭─ 🏆 𝐂𝐎𝐑𝐑𝐄𝐂𝐓\n" + "│ 🎉 অভিনন্দন! সঠিক উত্তর!\n" + "│ 🎯 উত্তর: " + selected + "\n" + "│ 🥇 স্ট্যাটাস: বিজয়ী\n" + "╰"; } else { resultText = "╭─ 💔 𝐖𝐑𝐎𝐍𝐆\n" + "│ 😢 আপনার উত্তর ভুল।\n" + "│ ✍️ আপনার উত্তর: " + selected + "\n" + "│ ✅ সঠিক উত্তর: " + Reply.answer + "\n" + "╰"; } try { const result = await api.sendMessage( resultText, threadID, messageID ); setTimeout(async function () { try { await api.unsendMessage(result.messageID); } catch (_) {} }, RESULT_DELETE_MS); await api.unsendMessage(Reply.messageID); } catch (_) {} } };