MCPcopy Create free account
hub / github.com/GlobalTechInfo/MEGA-MD / handler

Function handler

plugins/gcleave.js:8–40  ·  view source on GitHub ↗
(sock, message, args, context)

Source from the content-addressed store, hash-verified

6 usage: '.groupleave — leave current group\n.groupleave <jid> — leave specific group',
7 ownerOnly: true,
8 async handler(sock, message, args, context) {
9 const chatId = context.chatId || message.key.remoteJid;
10 const channelInfo = context.channelInfo || {};
11 const targetJid = args[0]?.includes('@g.us') ? args[0] : chatId;
12 if (!targetJid.endsWith('@g.us')) {
13 return await sock.sendMessage(chatId, {
14 text: `❌ This command only works in groups.\n\nTo leave a specific group: \`.groupleave 1234567890-1234567890@g.us\``,
15 ...channelInfo
16 }, { quoted: message });
17 }
18 try {
19 await sock.sendMessage(targetJid, {
20 text: `👋 *Bot is leaving the group.*\n\n_Goodbye everyone!_`,
21 ...channelInfo
22 });
23 await new Promise(r => setTimeout(r, 500));
24 await sock.groupLeave(targetJid);
25 // If triggered from another chat, confirm there
26 if (targetJid !== chatId) {
27 await sock.sendMessage(chatId, {
28 text: `✅ Left group: \`${targetJid}\``,
29 ...channelInfo
30 }, { quoted: message });
31 }
32 }
33 catch (e) {
34 console.error('[GROUPLEAVE] Error:', e.message);
35 await sock.sendMessage(chatId, {
36 text: `❌ Failed to leave group: ${e.message}`,
37 ...channelInfo
38 }, { quoted: message });
39 }
40 }
41};

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected