const fs = require("fs"); module.exports = { config: { name: "pending", version: "1.0.5", author: "ajmaul", aliases: [], role: 2, shortDescription: "Manage bot's waiting messages", longDescription: "Approve or cancel pending groups", category: "system", countDown: 10 }, languages: { "en": { "invaildNumber": "%1 ๐™ธ๐š‚ ๐™ฝ๐™พ๐šƒ ๐™ฐ ๐š…๐™ฐ๐™ป๐™ธ๐™ณ ๐™ฝ๐š„๐™ผ๐™ฑ๐™ด๐š", "cancelSuccess": "โŒ ๐š๐™ด๐™ต๐š„๐š‚๐™ด๐™ณ %1 ๐šƒ๐™ท๐š๐™ด๐™ฐ๐™ณ๐š‚!", "notiBox": "โœจ๐ŸŽ‰ ๐™ฒ๐™พ๐™ฝ๐™ถ๐š๐™ฐ๐šƒ๐š‚! ๐šˆ๐™พ๐š„๐š ๐™ถ๐š๐™พ๐š„๐™ฟ ๐™ท๐™ฐ๐š‚ ๐™ฑ๐™ด๐™ด๐™ฝ ๐™ฐ๐™ฟ๐™ฟ๐š๐™พ๐š…๐™ด๐™ณ! ๐ŸŽ‰โœจ\n๐Ÿš€ ๐š„๐š‚๐™ด !๐™ท๐™ด๐™ป๐™ฟ ๐šƒ๐™พ ๐™ด๐š‡๐™ฟ๐™ป๐™พ๐š๐™ด ๐™ฐ๐™ป๐™ป ๐™ฐ๐š…๐™ฐ๐™ธ๐™ป๐™ฐ๐™ฑ๐™ป๐™ด ๐™ฒ๐™พ๐™ผ๐™ผ๐™ฐ๐™ฝ๐™ณ๐š‚", "approveSuccess": "โœ… ๐™ฐ๐™ฟ๐™ฟ๐š๐™พ๐š…๐™ด๐™ณ %1 ๐šƒ๐™ท๐š๐™ด๐™ฐ๐™ณ๐š‚!", "cantGetPendingList": "โš ๏ธ ๐™ฒ๐™ฐ๐™ฝ'๐šƒ ๐™ถ๐™ด๐šƒ ๐šƒ๐™ท๐™ด ๐™ฟ๐™ด๐™ฝ๐™ณ๐™ธ๐™ฝ๐™ถ ๐™ป๐™ธ๐š‚๐šƒ!", "returnListPending": "ยปใ€Œ๐™ฟ๐™ด๐™ฝ๐™ณ๐™ธ๐™ฝ๐™ถใ€ยซโฎ ๐šƒ๐™พ๐šƒ๐™ฐ๐™ป ๐šƒ๐™ท๐š๐™ด๐™ฐ๐™ณ๐š‚ ๐šƒ๐™พ ๐™ฐ๐™ฟ๐™ฟ๐š๐™พ๐š…๐™ด: %1 โฏ\n\n%2", "returnListClean": "ใ€Œ๐™ฟ๐™ด๐™ฝ๐™ณ๐™ธ๐™ฝ๐™ถใ€๐šƒ๐™ท๐™ด๐š๐™ด ๐™ธ๐š‚ ๐™ฝ๐™พ ๐šƒ๐™ท๐š๐™ด๐™ฐ๐™ณ ๐™ธ๐™ฝ ๐šƒ๐™ท๐™ด ๐™ป๐™ธ๐š‚๐šƒ" } }, _getText: function(key, ...args) { const text = this.languages["en"][key] || key; return args.length ? text.replace("%1", args[0]).replace("%2", args[1] || "") : text; }, onStart: async function({ api, event }) { const { threadID, messageID, senderID } = event; let pendingList = []; try { const otherThreads = await api.getThreadList(100, null, ["OTHER"]) || []; const pendingThreads = await api.getThreadList(100, null, ["PENDING"]) || []; pendingList = [...otherThreads, ...pendingThreads].filter(group => group.isSubscribed && group.isGroup); } catch { return api.sendMessage(this._getText("cantGetPendingList"), threadID, messageID); } if (pendingList.length === 0) { return api.sendMessage(this._getText("returnListClean"), threadID, messageID); } let msg = ""; pendingList.forEach((group, index) => { msg += `${index + 1}/ ${group.name} (${group.threadID})\n`; }); return api.sendMessage(this._getText("returnListPending", pendingList.length, msg), threadID, (err, info) => { global.GoatBot.onReply.set(info.messageID, { commandName: this.config.name, messageID: info.messageID, author: senderID, pending: pendingList, unsendTimeout: setTimeout(() => { api.unsendMessage(info.messageID); }, this.config.countDown * 1000) }); }, messageID); }, onReply: async function({ event, Reply, api }) { const { author, pending, unsendTimeout } = Reply; if (String(event.senderID) !== String(author)) return; clearTimeout(unsendTimeout); const { body, threadID } = event; const input = body.trim().toLowerCase().split(/\s+/); let count = 0; const getText = this._getText.bind(this); if (input[0] === "c" || input[0] === "cancel") { for (let i = 1; i < input.length; i++) { const idx = parseInt(input[i]); if (isNaN(idx) || idx <= 0 || idx > pending.length) return api.sendMessage(getText("invaildNumber", input[i]), threadID); await api.removeUserFromGroup(api.getCurrentUserID(), pending[idx - 1].threadID); count++; } return api.sendMessage(getText("cancelSuccess", count), threadID); } else { for (let i = 0; i < input.length; i++) { const idx = parseInt(input[i]); if (isNaN(idx) || idx <= 0 || idx > pending.length) return api.sendMessage(getText("invaildNumber", input[i]), threadID); await api.sendMessage(getText("notiBox"), pending[idx - 1].threadID); count++; } return api.sendMessage(getText("approveSuccess", count), threadID); } } };