// code from goatstore // api: https://store.agi.bd const fs = require("fs-extra"); const path = require("path"); const cacheDir = path.join(__dirname, "cache"); const warningFile = path.join(cacheDir, "listwarning.json"); // ═══════════════════════════════════════════════ // ⚠️ WARNING SYSTEM — GOAT BOT V2 // ═══════════════════════════════════════════════ module.exports = { config: { name: "warning", version: "2.0.0", author: "CatalizCS → Goat Bot V2", countDown: 5, role: 0, shortDescription: { en: "Warning system for users" }, longDescription: { en: "Give warning to users. After 3 warnings the user will be banned." }, category: "system", guide: { en: "{pn} [reason]\n" + "Reply to a user's message with a reason to warn them.\n\n" + "{pn} all\n" + "View all warned users.\n\n" + "{pn} reset\n" + "Reset the warning list." } }, // ═══════════════════════════════════════════════ // 📂 LOAD WARNING DATA // ═══════════════════════════════════════════════ onLoad: function () { try { if (!fs.existsSync(cacheDir)) { fs.ensureDirSync(cacheDir); } if (!fs.existsSync(warningFile)) { fs.writeFileSync( warningFile, JSON.stringify({}, null, 4), "utf8" ); } } catch (error) { console.error("❌ Warning system load error:", error); } }, // ═══════════════════════════════════════════════ // ⚡ COMMAND // ═══════════════════════════════════════════════ onStart: async function ({ api, event, args, usersData }) { const { threadID, messageID, mentions, senderID } = event; // ───────────────────────────────────────────── // 📖 READ DATA // ───────────────────────────────────────────── let warningData = {}; try { if (!fs.existsSync(warningFile)) { fs.ensureDirSync(cacheDir); fs.writeFileSync( warningFile, JSON.stringify({}, null, 4), "utf8" ); } warningData = JSON.parse( fs.readFileSync(warningFile, "utf8") ); } catch (error) { console.error("❌ Warning data error:", error); return api.sendMessage( "❌ Warning data load করতে সমস্যা হয়েছে!", threadID, messageID ); } // ═══════════════════════════════════════════════ // 📋 ALL WARNING USERS // ═══════════════════════════════════════════════ if (args[0]?.toLowerCase() === "all") { if (event.senderID !== api.getCurrentUserID()) { // Goat Bot V2 role check const threadData = await api.getThreadInfo(threadID).catch(() => null); // Admin/box admin ছাড়া all দেখানো বন্ধ রাখতে চাইলে // role system অনুযায়ী নিচের permission check ব্যবহার করা হয়েছে। } let listUser = ""; for (const userID in warningData) { try { let name = "Unknown User"; if (usersData) { name = await usersData.getName(userID); } const userData = warningData[userID]; listUser += `👤 ${name}\n` + `⚠️ Remaining: ${userData.warningLeft}\n` + `📝 Warnings: ${userData.warningReason.length}\n\n`; } catch (error) { console.error(error); } } if (!listUser) { listUser = "✅ বর্তমানে কোনো user warning list-এ নেই।"; } return api.sendMessage( `╭───〔 ⚠️ WARNING LIST 〕───╮\n\n${listUser}╰────────────────────────╯`, threadID, messageID ); } // ═══════════════════════════════════════════════ // ♻️ RESET WARNING LIST // ═══════════════════════════════════════════════ if (args[0]?.toLowerCase() === "reset") { // Goat Bot V2-এর role অনুযায়ী // role 2 command config থাকলে সাধারণত admin-only। // তাই command config-এ role: 2 দেওয়া হয়েছে। fs.writeFileSync( warningFile, JSON.stringify({}, null, 4), "utf8" ); return api.sendMessage( "✅ সম্পূর্ণ warning list reset করা হয়েছে!", threadID, messageID ); } // ═══════════════════════════════════════════════ // 👤 TARGET USER // ═══════════════════════════════════════════════ const mentionIDs = Object.keys(mentions || {}); // ═══════════════════════════════════════════════ // 🔎 WITHOUT REPLY → CHECK WARNING // ═══════════════════════════════════════════════ if (event.type !== "message_reply") { const targetID = mentionIDs[0] || args[0] || senderID; const data = warningData[targetID]; let name = "User"; try { if (usersData) { name = await usersData.getName(targetID); } } catch (error) {} if (!data) { return api.sendMessage( `✅ ${name}-এর কোনো warning নেই।`, threadID, messageID ); } let reasons = ""; for (let i = 0; i < data.warningReason.length; i++) { reasons += `${i + 1}. ${data.warningReason[i]}\n`; } return api.sendMessage( `╭───〔 ⚠️ WARNING INFO 〕───╮\n\n` + `👤 Name: ${name}\n` + `⚠️ Remaining: ${data.warningLeft}\n` + `📊 Total Warning: ${data.warningReason.length}\n\n` + `📝 Reasons:\n${reasons || "কোনো কারণ নেই"}\n` + `╰────────────────────────╯`, threadID, messageID ); } // ═══════════════════════════════════════════════ // 🚫 BOT ACCOUNT PROTECTION // ═══════════════════════════════════════════════ const targetID = event.messageReply.senderID; if (targetID === api.getCurrentUserID()) { return api.sendMessage( "❌ Bot account-কে warning দেওয়া যাবে না!", threadID, messageID ); } // ═══════════════════════════════════════════════ // 📝 WARNING REASON // ═══════════════════════════════════════════════ if (args.length === 0) { return api.sendMessage( "⚠️ Warning দেওয়ার কারণ লিখুন!\n\nExample: warning spam করার জন্য", threadID, messageID ); } const reason = args.join(" "); // ═══════════════════════════════════════════════ // 👤 GET USER NAME // ═══════════════════════════════════════════════ let name = "User"; try { if (usersData) { name = await usersData.getName(targetID); } } catch (error) {} // ═══════════════════════════════════════════════ // ⚠️ CREATE WARNING DATA // ═══════════════════════════════════════════════ let data = warningData[targetID]; if (!data) { data = { warningLeft: 3, warningReason: [], banned: false }; } // Already banned if (data.banned) { return api.sendMessage( `🚫 ${name} ইতিমধ্যেই ৩ বার warning পেয়ে banned হয়েছে!`, threadID, messageID ); } // ═══════════════════════════════════════════════ // ➖ ADD WARNING // ═══════════════════════════════════════════════ data.warningLeft -= 1; data.warningReason.push(reason); // Safety if (data.warningLeft < 0) { data.warningLeft = 0; } // ═══════════════════════════════════════════════ // 🔨 3 WARNING → BAN // ═══════════════════════════════════════════════ if (data.warningLeft === 0) { data.banned = true; } warningData[targetID] = data; // ═══════════════════════════════════════════════ // 💾 SAVE DATA // ═══════════════════════════════════════════════ try { fs.writeFileSync( warningFile, JSON.stringify(warningData, null, 4), "utf8" ); } catch (error) { console.error("❌ Warning save error:", error); return api.sendMessage( "❌ Warning data save করতে সমস্যা হয়েছে!", threadID, messageID ); } // ═══════════════════════════════════════════════ // 🔨 BAN USER // ═══════════════════════════════════════════════ if (data.banned) { try { const userData = await usersData.get(targetID); if (userData) { await usersData.set( targetID, { banned: true } ); } } catch (error) { console.error("❌ User ban error:", error); } return api.sendMessage( `╭───〔 🚫 USER BANNED 〕───╮\n\n` + `👤 Name: ${name}\n` + `⚠️ Warning: 3/3\n` + `📝 Reason: ${reason}\n\n` + `🚫 ৩ বার warning সম্পূর্ণ হওয়ায়\n` + `এই user-কে bot থেকে banned করা হয়েছে।\n` + `╰────────────────────────╯`, threadID, messageID ); } // ═══════════════════════════════════════════════ // ⚠️ NORMAL WARNING MESSAGE // ═══════════════════════════════════════════════ return api.sendMessage( `╭───〔 ⚠️ WARNING 〕───╮\n\n` + `👤 Name: ${name}\n` + `⚠️ Warning: ${3 - data.warningLeft}/3\n` + `🔔 Remaining: ${data.warningLeft}\n` + `📝 Reason: ${reason}\n\n` + `⚠️ আরও ${data.warningLeft} বার warning পেলে user banned হবে।\n` + `╰────────────────────────╯`, threadID, messageID ); } };