// code from goatstore // api: https://store.agi.bd const fs = require("fs-extra"); const moment = require("moment-timezone"); const path = require("path"); const iconPath = path.join(__dirname, "emoji.json"); if (!fs.existsSync(iconPath)) fs.writeFileSync(iconPath, JSON.stringify({})); module.exports = { config: { name: "update", version: "1.1.0", author: "rX (converted for GoatBot V2)", category: "events", envConfig: { sendNoti: true } }, onStart: async function ({ api, event, threadsData, usersData, message, envEvents }) { const { threadID, logMessageType, logMessageData = {}, author } = event; // E2EE / JID style thread skip if (typeof threadID === "string" && threadID.includes("@")) return; // Thread data check (adminUpdate off থাকলে স্কিপ) const threadData = await threadsData.get(threadID).catch(() => null); if (!threadData) return; const settings = threadData.data || {}; if (settings.adminUpdate === false) return; const sendNoti = envEvents?.update?.sendNoti !== false; // Avatar effect helper const AVATAR_EFFECTS = ["avatar_love", "avatar_cry", "avatar_laugh", "avatar_angry"]; const notify = (body) => { if (!sendNoti) return; const effect = AVATAR_EFFECTS[Math.floor(Math.random() * AVATAR_EFFECTS.length)]; try { api.sendMessage({ body, textEffect: effect }, threadID, (err) => { if (err) api.sendMessage(body, threadID); }); } catch (e) { api.sendMessage(body, threadID); } }; // Bold Unicode converter const boldMap = { A: "𝗔", B: "𝗕", C: "𝗖", D: "𝗗", E: "𝗘", F: "𝗙", G: "𝗚", H: "𝗛", I: "𝗜", J: "𝗝", K: "𝗞", L: "𝗟", M: "𝗠", N: "𝗡", O: "𝗢", P: "𝗣", Q: "𝗤", R: "𝗥", S: "𝗦", T: "𝗧", U: "𝗨", V: "𝗩", W: "𝗪", X: "𝗫", Y: "𝗬", Z: "𝗭", a: "𝗮", b: "𝗯", c: "𝗰", d: "𝗱", e: "𝗲", f: "𝗳", g: "𝗴", h: "𝗵", i: "𝗶", j: "𝗷", k: "𝗸", l: "𝗹", m: "𝗺", n: "𝗻", o: "𝗼", p: "𝗽", q: "𝗾", r: "𝗿", s: "𝘀", t: "𝘁", u: "𝘂", v: "𝘃", w: "𝘄", x: "𝘅", y: "𝘆", z: "𝘇", "0": "𝟬", "1": "𝟭", "2": "𝟮", "3": "𝟯", "4": "𝟰", "5": "𝟱", "6": "𝟲", "7": "𝟳", "8": "𝟴", "9": "𝟵" }; const toBold = (text) => { if (text == null) return ""; return String(text).split("").map(c => boldMap[c] || c).join(""); }; const getName = async (uid) => { try { return await usersData.getName(uid) || "Unknown"; } catch { return "Unknown"; } }; const time = moment.tz("Asia/Dhaka").format("DD/MM/YYYY HH:mm:ss"); try { switch (logMessageType) { // ========== ADMIN CHANGE ========== case "log:thread-admins": { const { ADMIN_EVENT, TARGET_ID } = logMessageData; const authorName = await getName(author); const targetName = await getName(TARGET_ID); // Update admin list in database const threadInfo = await api.getThreadInfo(threadID).catch(() => null); if (threadInfo?.adminIDs) { const adminIDs = threadInfo.adminIDs.map(item => item.id); await threadsData.set(threadID, { adminIDs }, "data"); } if (ADMIN_EVENT === "add_admin") { notify( `👑 ${toBold("New Admin")}\n` + `➤ ${toBold(targetName)} কে অ্যাডমিন বানানো হয়েছে\n` + `➤ By: ${toBold(authorName)}\n` + `🕒 ${time}` ); } else if (ADMIN_EVENT === "remove_admin") { notify( `❌ ${toBold("Admin Removed")}\n` + `➤ ${toBold(targetName)} কে অ্যাডমিন থেকে সরানো হয়েছে\n` + `➤ By: ${toBold(authorName)}\n` + `🕒 ${time}` ); } break; } // ========== THREAD NAME CHANGE ========== case "log:thread-name": { const newName = logMessageData.name || "Unnamed"; const authorName = await getName(author); await threadsData.set(threadID, { threadName: newName }); notify( `📝 ${toBold("Group Name Changed")}\n` + `➤ New Name: ${toBold(newName)}\n` + `➤ By: ${toBold(authorName)}\n` + `🕒 ${time}` ); break; } // ========== NICKNAME CHANGE ========== case "log:user-nickname": { const { participant_id, nickname } = logMessageData; const authorName = await getName(author); const targetName = await getName(participant_id); const newNick = nickname || "Removed"; notify( `✏️ ${toBold("Nickname Changed")}\n` + `➤ User: ${toBold(targetName)}\n` + `➤ New Nickname: ${toBold(newNick)}\n` + `➤ By: ${toBold(authorName)}\n` + `🕒 ${time}` ); break; } // ========== THREAD ICON / EMOJI ========== case "log:thread-icon": { const authorName = await getName(author); const newIcon = logMessageData.thread_icon || logMessageData.emoji || "❓"; // Save emoji const emojiData = JSON.parse(fs.readFileSync(iconPath, "utf8")); emojiData[threadID] = newIcon; fs.writeFileSync(iconPath, JSON.stringify(emojiData, null, 2)); await threadsData.set(threadID, { emoji: newIcon }, "data"); notify( `😀 ${toBold("Group Emoji Changed")}\n` + `➤ New Emoji: ${newIcon}\n` + `➤ By: ${toBold(authorName)}\n` + `🕒 ${time}` ); break; } // ========== THREAD COLOR / THEME ========== case "log:thread-color": { const authorName = await getName(author); const newColor = logMessageData.theme_color || logMessageData.color_id || "Unknown"; await threadsData.set(threadID, { threadThemeID: newColor }, "data"); notify( `🎨 ${toBold("Theme Color Changed")}\n` + `➤ New Color: ${toBold(newColor)}\n` + `➤ By: ${toBold(authorName)}\n` + `🕒 ${time}` ); break; } // ========== CALL ========== case "log:thread-call": { // Optional: call related notification // চাইলে এখানে যোগ করতে পারো break; } default: break; } } catch (err) { console.error("[update event error]", err); } } };