// code from goatstore // api: https://store.agi.bd const moment = require("moment-timezone"); module.exports = { config: { name: "pending", version: "2.3", author: "xalman", countDown: 5, role: 2, shortDescription: { en: "Manage pending group requests" }, longDescription: { en: "Approve or refuse groups waiting for bot permission" }, category: "owner" }, langs: { en: { invalid: "โŒ Invalid selection: %1", refused: "๐Ÿšซ %1 group request refused\nโฐ Time: %2", approved: "โœ… %1 group successfully approved\nโฐ Time: %2", fetchFail: "โŒ Unable to load pending groups", list: "๐Ÿ”” PENDING GROUPS (%1)\n\n%2\n\n๐Ÿ‘‰ Reply with number(s) to approve\n๐Ÿ‘‰ Reply `c ` to cancel", empty: "โœ… No pending groups found" } }, onReply: async ({ api, event, Reply, getLang }) => { if (event.senderID != Reply.author) return; const input = event.body.trim(); const { threadID, messageID } = event; const prefix = global.GoatBot?.config?.prefix || "-"; const botNickname = "๐˜๐Ž๐”๐‘ โ™ฒ๏ธŽ๏ธŽ๏ธŽ ๐๐๐™ โ™ก๏ธŽโ™ฅ๏ธŽ"; let done = 0; const dateTime = moment() .tz("Asia/Dhaka") .format("ddd, YYYY-MMM-DD, HH:mm:ss"); if (/^(c|cancel)/i.test(input)) { const nums = input.replace(/^(c|cancel)/i, "").trim().split(/\s+/); for (const n of nums) { if (!Number(n) || n < 1 || n > Reply.queue.length) return api.sendMessage(getLang("invalid", n), threadID, messageID); const targetThreadID = Reply.queue[n - 1].threadID; api.sendMessage( `โ•ญโ”€๐Ÿšซ ACCESS DENIED ๐Ÿšซโ”€โ•ฎ โ”‚ ๐Ÿค– Bot : Refused โ”‚ ๐Ÿ”— Prefix : ${prefix} โ”‚ โšก Owner : ๐Œ๐€๐Œ๐”๐ โ”‚ โฐ Date/Time : ${dateTime} โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ`, targetThreadID ); await api.removeUserFromGroup(api.getCurrentUserID(), targetThreadID); done++; } return api.sendMessage( getLang("refused", done, dateTime), threadID, messageID ); } const nums = input.split(/\s+/); for (const n of nums) { if (!Number(n) || n < 1 || n > Reply.queue.length) return api.sendMessage(getLang("invalid", n), threadID, messageID); const targetThreadID = Reply.queue[n - 1].threadID; const botID = api.getCurrentUserID(); api.sendMessage( `โ•ญโ”€โœจ SYSTEM GOAT โœจโ”€โ•ฎ โ”‚ ๐Ÿค– Bot : Activated โ”‚ ๐Ÿ”— Prefix : ${prefix} โ”‚ โšก Owner : ๐Œ๐€๐Œ๐”๐ โ”‚ โฐ Date/Time : ${dateTime} โ•ฐโ”€โœ… Access Grantedโ”€โ•ฏ`, targetThreadID ); try { await api.changeNickname(botNickname, targetThreadID, botID); } catch (e) { console.log(`Nickname set error for ${targetThreadID}: `, e); } done++; } return api.sendMessage( getLang("approved", done, dateTime), threadID, messageID ); }, onStart: async ({ api, event, getLang, commandName }) => { const { threadID, messageID, senderID } = event; let text = ""; let i = 1; try { const other = await api.getThreadList(100, null, ["OTHER"]) || []; const pending = await api.getThreadList(100, null, ["PENDING"]) || []; const groups = [...other, ...pending].filter( t => t.isGroup && t.isSubscribed ); if (!groups.length) return api.sendMessage(getLang("empty"), threadID, messageID); for (const g of groups) text += `${i++}. ${g.name || "Unnamed Group"} โ†’ ${g.threadID}\n`; api.sendMessage( getLang("list", groups.length, text), threadID, (err, info) => { global.GoatBot.onReply.set(info.messageID, { commandName, author: senderID, queue: groups }); }, messageID ); } catch (err) { return api.sendMessage(getLang("fetchFail"), threadID, messageID); } } };