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

Function handler

plugins/ban.js:42–98  ·  view source on GitHub ↗
(sock, message, args, context)

Source from the content-addressed store, hash-verified

40 description: 'Ban a user from using the bot',
41 usage: '.ban @user or reply to message',
42 async handler(sock, message, args, context) {
43 const chatId = context.chatId || message.key.remoteJid;
44 const channelInfo = context.channelInfo || {};
45 const _isGroup = context.isGroup;
46 let userToBan;
47 if (message.message?.extendedTextMessage?.contextInfo?.mentionedJid?.length > 0) {
48 userToBan = message.message.extendedTextMessage.contextInfo.mentionedJid[0];
49 }
50 else if (message.message?.extendedTextMessage?.contextInfo?.participant) {
51 userToBan = message.message.extendedTextMessage.contextInfo.participant;
52 }
53 if (!userToBan) {
54 await sock.sendMessage(chatId, {
55 text: '❌ *Please mention a user or reply to their message*\n\nUsage: `.ban @user` or reply with `.ban`',
56 ...channelInfo
57 }, { quoted: message });
58 return;
59 }
60 try {
61 const botId = `${sock.user.id.split(':')[0] }@s.whatsapp.net`;
62 if (userToBan === botId || userToBan === botId.replace('@s.whatsapp.net', '@lid')) {
63 await sock.sendMessage(chatId, {
64 text: '❌ *Cannot ban the bot account*',
65 ...channelInfo
66 }, { quoted: message });
67 return;
68 }
69 }
70 catch (e) { }
71 try {
72 const bannedUsers = await getBannedUsers();
73 if (!bannedUsers.includes(userToBan)) {
74 bannedUsers.push(userToBan);
75 await saveBannedUsers(bannedUsers);
76 await sock.sendMessage(chatId, {
77 text: `🚫 *User Banned Successfully!*\n\n@${userToBan.split('@')[0]} has been banned from using the bot.\n\n` +
78 `*Storage:* ${HAS_DB ? 'Database' : 'File System'}`,
79 mentions: [userToBan],
80 ...channelInfo
81 }, { quoted: message });
82 }
83 else {
84 await sock.sendMessage(chatId, {
85 text: `⚠️ *Already Banned*\n\n@${userToBan.split('@')[0]} is already banned!`,
86 mentions: [userToBan],
87 ...channelInfo
88 }, { quoted: message });
89 }
90 }
91 catch (error) {
92 console.error('Error in ban command:', error);
93 await sock.sendMessage(chatId, {
94 text: '❌ *Failed to ban user!*\n\nPlease try again.',
95 ...channelInfo
96 }, { quoted: message });
97 }
98 }
99};

Callers

nothing calls this directly

Calls 2

getBannedUsersFunction · 0.70
saveBannedUsersFunction · 0.70

Tested by

no test coverage detected