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

Function handler

plugins/unban.ts:44–116  ·  view source on GitHub ↗
(sock: any, message: any, args: any, context: BotContext)

Source from the content-addressed store, hash-verified

42 ownerOnly: false,
43
44 async handler(sock: any, message: any, args: any, context: BotContext) {
45 const { chatId, isGroup, channelInfo, senderIsOwnerOrSudo, isSenderAdmin, isBotAdmin } = context;
46
47 if (isGroup) {
48 if (!isBotAdmin) {
49 await sock.sendMessage(chatId, {
50 text: 'Please make the bot an admin to use .unban',
51 ...channelInfo
52 }, { quoted: message });
53 return;
54 }
55 if (!isSenderAdmin && !message.key.fromMe && !senderIsOwnerOrSudo) {
56 await sock.sendMessage(chatId, {
57 text: 'Only group admins can use .unban',
58 ...channelInfo
59 }, { quoted: message });
60 return;
61 }
62 } else {
63 if (!message.key.fromMe && !senderIsOwnerOrSudo) {
64 await sock.sendMessage(chatId, {
65 text: 'Only owner/sudo can use .unban in private chat',
66 ...channelInfo
67 }, { quoted: message });
68 return;
69 }
70 }
71
72 let userToUnban;
73
74 if (message.message?.extendedTextMessage?.contextInfo?.mentionedJid?.length > 0) {
75 userToUnban = message.message.extendedTextMessage.contextInfo.mentionedJid[0];
76 }
77 else if (message.message?.extendedTextMessage?.contextInfo?.participant) {
78 userToUnban = message.message.extendedTextMessage.contextInfo.participant;
79 }
80
81 if (!userToUnban) {
82 await sock.sendMessage(chatId, {
83 text: 'Please mention the user or reply to their message to unban!',
84 ...channelInfo
85 }, { quoted: message });
86 return;
87 }
88
89 try {
90 const bannedUsers = await getBannedUsers();
91 const index = bannedUsers.indexOf(userToUnban);
92
93 if (index > -1) {
94 bannedUsers.splice(index, 1);
95 await saveBannedUsers(bannedUsers);
96
97 await sock.sendMessage(chatId, {
98 text: `✅ Successfully unbanned @${userToUnban.split('@')[0]}!\n\nStorage: ${HAS_DB ? 'Database' : 'File System'}`,
99 mentions: [userToUnban],
100 ...channelInfo
101 }, { quoted: message });

Callers

nothing calls this directly

Calls 2

getBannedUsersFunction · 0.70
saveBannedUsersFunction · 0.70

Tested by

no test coverage detected