// code from goatstore // api: https://store.agi.bd const axios = require("axios"); exports.config = { name: "quiz", version: "2.0", author: "—͞𝐏ʀɪᴍᴇ́", countDown: 10, role: 0, shortDescription: "Quiz with category & balance", longDescription: "Category quiz, Bangla quiz, and money reward", category: "game", guide: { en: "{pn} - random quiz\n{pn} bangla - bangla quiz\n{pn} science / history / geography / anime / general / sports / computer\nExample: {pn} science" } }; const categoriesMap = { general: 9, science: 17, computer: 18, history: 23, geography: 22, sports: 21, anime: 31, animals: 27, vehicle: 28 }; // Bangla Quiz Local Database const banglaQuiz = [ { q: "বাংলাদেশের জাতীয় ফুল কি?", options: ["গোলাপ", "শাপলা", "জবা", "বেলি"], ans: "B" }, { q: "বাংলাদেশের স্বাধীনতা দিবস কবে?", options: ["১৬ ডিসেম্বর", "২৬ মার্চ", "২১ ফেব্রুয়ারি", "৭ মার্চ"], ans: "B" }, { q: "পদ্মা সেতুর দৈর্ঘ্য কত?", options: ["৫.৫ কিমি", "৬.১৫ কিমি", "৬.৫ কিমি", "৭ কিমি"], ans: "B" }, { q: "বাংলা ভাষার প্রথম উপন্যাস কোনটি?", options: ["দুর্গেশনন্দিনী", "আলালের ঘরের দুলাল", "পথের পাঁচালী", "কপালকুণ্ডলা"], ans: "B" }, { q: "কম্পিউটারের মস্তিষ্ক বলা হয় কোনটিকে?", options: ["RAM", "CPU", "Hard Disk", "Motherboard"], ans: "B" }, { q: "বাংলাদেশের জাতীয় সংসদ ভবনের স্থপতি কে?", options: ["লুই আই কান", "মাজহারুল ইসলাম", "ফজলুর রহমান খান", "সত্যজিৎ রায়"], ans: "A" }, { q: "WiFi এর পূর্ণরূপ কি?", options: ["Wireless Fidelity", "Wired Fidelity", "Wireless Function", "Web Fidelity"], ans: "A" }, { q: "ফেসবুক প্রতিষ্ঠিত হয় কত সালে?", options: ["২০০২", "২০০৪", "২০০৬", "২০০৮"], ans: "B" }, ]; function decode(str) { try { return decodeURIComponent(str); } catch { return str; } } exports.onStart = async function({ api, event, args, message, usersData }) { const input = (args[0] || "random").toLowerCase(); let question, options, correctLetter, correctAnswer; // === BANGLA QUIZ === if (input === "bangla" || input === "bn") { const random = banglaQuiz[Math.floor(Math.random() * banglaQuiz.length)]; question = random.q; options = random.options; correctLetter = random.ans; correctAnswer = random.options[["A","B","C","D"].indexOf(random.ans)]; let optionText = ""; ["A","B","C","D"].forEach((l, i) => { optionText += `${l}. ${options[i]}\n`; }); const body = `❓ বাংলা কুইজ ❓\n━━━━━━━━━━━━━━━━━━━━\n${question}\n━━━━━━━━━━━━━━━━━━━━\n${optionText}\n━━━━━━━━━━━━━━━━━━━━\nReply A/B/C/D\nReward: 100 coins`; return message.reply(body, (err, info) => { global.GoatBot.onReply.set(info.messageID, { commandName: "quiz", author: event.senderID, correct: correctLetter, answer: correctAnswer, reward: 100 }); }); } // === ENGLISH API QUIZ WITH CATEGORY === let catId = categoriesMap[input] || ""; let url = `https://opentdb.com/api.php?amount=1&type=multiple&encode=url3986${catId? `&category=${catId}` : ""}`; try { const res = await axios.get(url, { timeout: 10000 }); const data = res.data.results[0]; if (!data) throw new Error("no data"); question = decode(data.question); correctAnswer = decode(data.correct_answer); const incorrect = data.incorrect_answers.map(a => decode(a)); let allOptions = [...incorrect, correctAnswer]; allOptions.sort(() => Math.random() - 0.5); const letters = ["A","B","C","D"]; let optionText = ""; allOptions.forEach((opt, i) => { optionText += `${letters[i]}. ${opt}\n`; if (opt === correctAnswer) correctLetter = letters[i]; }); const body = `❓ QUIZ [${input.toUpperCase()}] ❓\n━━━━━━━━━━━━━━━━━━━━\n${question}\n━━━━━━━━━━━━━━━━━━━━\n${optionText}\n━━━━━━━━━━━━━━━━━━━━\nReply A/B/C/D\nReward: 200 coins`; return message.reply(body, (err, info) => { global.GoatBot.onReply.set(info.messageID, { commandName: "quiz", author: event.senderID, correct: correctLetter, answer: correctAnswer, reward: 200 }); }); } catch (e) { console.log(e); return message.reply("❌ Failed to fetch quiz. Try: quiz bangla"); } }; exports.onReply = async function({ event, Reply, message, usersData, api }) { if (event.senderID!= Reply.author) return; const userAns = (event.body || "").trim().toUpperCase(); if (!["A","B","C","D"].includes(userAns)) { return message.reply("Please reply with A, B, C or D."); } try { if (userAns === Reply.correct) { // add balance if (usersData) { await usersData.addMoney(event.senderID, Reply.reward); const userInfo = await usersData.get(event.senderID); const newBal = userInfo.money || 0; message.reply(`✅ Correct! 🎉\nAnswer: ${Reply.answer} (${Reply.correct})\n💰 You got ${Reply.reward} coins!\nNew Balance: ${newBal}`); } else { message.reply(`✅ Correct! 🎉\nAnswer: ${Reply.answer} (${Reply.correct})\n💰 You got ${Reply.reward} coins!`); } } else { message.reply(`❌ Wrong!\nCorrect was ${Reply.answer} (${Reply.correct})\nBetter luck next time!`); } } catch (e) { console.log(e); message.reply(`Result: ${userAns === Reply.correct? "Correct" : "Wrong"}. Answer: ${Reply.answer}`); } global.GoatBot.onReply.delete(Reply.messageID); };