// code from goatstore // api: https://store.agi.bd module.exports = { config: { name: "listbox", version: "1.3.1", author: "RS RIFAT", role: 2, countDown: 10, shortDescription: { en: "List all groups bot is in and make bot leave", }, longDescription: { en: "Shows all group names where the bot is present. Reply with a group number to force the bot to leave that group.", }, category: "system", guide: { en: "{pn} -> Reply with group number to make bot leave", }, }, onReply: async function ({ api, event, Reply }) { const { author, groupThreads } = Reply; const { senderID, threadID, messageID, body } = event; if (senderID !== author) { return api.sendMessage("āš ļø š—¢š—»š—¹š˜† š˜š—µš—² š—°š—¼š—ŗš—ŗš—®š—»š—± š˜‚š˜€š—²š—æ š—°š—®š—» š—æš—²š—½š—¹š˜†!", threadID, messageID); } const choice = parseInt(body); if (isNaN(choice) || choice < 1 || choice > groupThreads.length) { return api.sendMessage( `āŒ š—œš—»š˜ƒš—®š—¹š—¶š—± š—°š—µš—¼š—¶š—°š—²!\n Please enter a number between 1 and ${groupThreads.length}.`, threadID, messageID ); } const selectedGroup = groupThreads[choice - 1]; const botID = api.getCurrentUserID(); try { // 1. Send stylish notice to target group before leaving const leaveNoticeMsg = `╭━━━〔 āš ļø š—•š—¢š—§ š—Ÿš—˜š—”š—©š—œš—”š—š āš ļøļø 〕━━━╮\n` + `│ \n` + `│ šŸ“¢ š—”š˜š˜š—²š—»š˜š—¶š—¼š—» š—˜š˜ƒš—²š—æš˜†š—¼š—»š—²!\n` + `│ šŸ¤– š—§š—µš—¶š˜€ š—Æš—¼š˜ š—¶š˜€ š—¹š—²š—®š˜ƒš—¶š—»š—“ š˜š—µš—¶š˜€ š—“š—æš—¼š˜‚š—½\n` + `│ šŸ‘‘ š—”š—°š˜š—¶š—¼š—» š—œš˜€š˜€š˜‚š—²š—± š—•š˜†: Admin\n` + `│ \n` + `╰━━━━━━━━━━━━━━━━━━━━━━╯\n` + ` šŸ‘‹ š—šš—¼š—¼š—±š—Æš˜†š—² & Take Care! ā¤ļøļø`; try { await api.sendMessage(leaveNoticeMsg, selectedGroup.threadID); } catch (e) { // Continue even if sending message to target group fails } // 2. Make the bot leave the group await api.removeUserFromGroup(botID, selectedGroup.threadID); // 3. Stylish response to the admin const successMsg = `╭━━━〔 🚪 š—Ÿš—˜š—”š—©š—˜ š—¦š—Øš—–š—–š—˜š—¦š—¦ 〕━━━╮\n` + `│ \n` + `│ āœ… š—¦š˜‚š—°š—°š—²š˜€š˜€š—³š˜‚š—¹š—¹š˜† š—Ÿš—²š—³š˜ š—šš—æš—¼š˜‚š—½!\n` + `│ \n` + `│ šŸ“Œ š—”š—®š—ŗš—²: ${selectedGroup.name}\n` + `│ šŸ†” š—§š—µš—æš—²š—®š—± š—œš——: ${selectedGroup.threadID}\n` + `│ \n` + `╰━━━━━━━━━━━━━━━━━━━━━━╯`; return api.sendMessage(successMsg, threadID, messageID); } catch (error) { const errorMsg = `╭━━━〔 āŒ š—Ÿš—˜š—”š—©š—˜ š—™š—”š—œš—Ÿš—˜š—— 〕━━━╮\n` + `│ \n` + `│ āš ļø Couldn't leave group!\n` + `│ šŸ“Œ Group: ${selectedGroup.name}\n` + `│ šŸ“ Reason: ${error.message || error}\n` + `│ \n` + `╰━━━━━━━━━━━━━━━━━━━━━━╯`; return api.sendMessage(errorMsg, threadID, messageID); } }, onStart: async function ({ api, event, commandName, threadsData }) { const botID = api.getCurrentUserID(); try { let dbThreads = []; if (threadsData && typeof threadsData.getAll === "function") { try { dbThreads = await threadsData.getAll(); } catch (e) { console.error(e); } } if (!dbThreads.length && global.db && Array.isArray(global.db.allThreadData)) { dbThreads = global.db.allThreadData; } const dbGroupMap = new Map(); if (Array.isArray(dbThreads)) { for (const t of dbThreads) { if (t && t.isGroup && !t.threadID?.includes("@msgr")) { const isBotInGroup = Array.isArray(t.members) ? t.members.some(m => m.userID == botID && m.inGroup !== false) : true; if (isBotInGroup) { dbGroupMap.set(String(t.threadID), t); } } } } let liveThreads = []; if (api && typeof api.getThreadList === "function") { try { const fetched = await api.getThreadList(100, null, ["INBOX"]); if (Array.isArray(fetched)) { liveThreads = fetched.filter(t => t && t.isGroup && !t.threadID?.includes("@msgr")); } } catch (e) { console.error(e); } } let groupThreads = []; if (liveThreads.length > 0) { groupThreads = liveThreads.map(t => { const tid = String(t.threadID); const dbData = dbGroupMap.get(tid); return { threadID: tid, name: t.threadName || t.name || dbData?.threadName || dbData?.name || "Unnamed Group" }; }); } else { groupThreads = Array.from(dbGroupMap.values()).map(t => ({ threadID: String(t.threadID), name: t.threadName || t.name || "Unnamed Group" })); } if (groupThreads.length === 0) { return api.sendMessage("āŒ No groups found.", event.threadID, event.messageID); } let msg = `šŸŽÆ š—§š—¼š˜š—®š—¹ š—šš—æš—¼š˜‚š—½š˜€: ${groupThreads.length}\n━━━━━━━━━━━━━━\n`; groupThreads.forEach((group, index) => { msg += `šŸ“¦ š—šš—æš—¼š˜‚š—½ ${index + 1}:\n`; msg += `šŸ“Œ š—”š—®š—ŗš—²: ${group.name}\n`; msg += `šŸ†” š—§š—µš—æš—²š—®š—± š—œš——: ${group.threadID}\n`; msg += `━━━━━━━━━━━━━━\n`; }); msg += `\nšŸ‘‰ Reply to this message with the group number to make the bot LEAVE that group! (Example: 1)`; return api.sendMessage(msg, event.threadID, (err, info) => { if (err) return console.error(err); if (global.GoatBot && global.GoatBot.onReply) { global.GoatBot.onReply.set(info.messageID, { commandName, author: event.senderID, groupThreads }); } else if (global.client && global.client.handleReply) { global.client.handleReply.push({ name: commandName, messageID: info.messageID, author: event.senderID, groupThreads }); } }, event.messageID); } catch (error) { return api.sendMessage( `āš ļø Error while fetching group list:\n${error.message}`, event.threadID, event.messageID ); } }, };