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

Function handler

plugins/antispam.ts:286–367  ·  view source on GitHub ↗
(sock: any, message: any, args: any[], context: BotContext)

Source from the content-addressed store, hash-verified

284 adminOnly: true,
285
286 async handler(sock: any, message: any, args: any[], context: BotContext) {
287 const chatId = context.chatId || message.key.remoteJid;
288 const channelInfo = context.channelInfo || {};
289 const isBotAdmin = context.isBotAdmin || false;
290
291 const config = await loadConfig();
292 if (!config.groups[chatId]) config.groups[chatId] = { ...DEFAULT_GROUP_CONFIG };
293 const groupConfig = config.groups[chatId];
294 const action = args[0]?.toLowerCase();
295
296 if (!action || action === 'status') {
297 return await sock.sendMessage(chatId, {
298 text: `*🛡️ ANTI-SPAM STATUS*\n\n` +
299 `*Status:* ${groupConfig.enabled ? '✅ Enabled' : '❌ Disabled'}\n` +
300 `*Limit:* ${groupConfig.maxMessages} messages in ${groupConfig.windowSeconds}s\n` +
301 `*Action:* ${groupConfig.action.toUpperCase()}\n` +
302 `*Warn limit:* ${groupConfig.warnCount} warns before kick\n` +
303 `*Bot is admin:* ${isBotAdmin ? '✅ Yes' : '❌ No (needed for kick/mute)'}\n\n` +
304 `*Commands:*\n` +
305 `• \`.antispam on/off\`\n` +
306 `• \`.antispam set 5 10\` — 5 msgs in 10s\n` +
307 `• \`.antispam action warn/kick/mute\`\n` +
308 `• \`.antispam warns 3\` — warns before kick`,
309 ...channelInfo
310 }, { quoted: message });
311 }
312
313 if (action === 'on' || action === 'enable') {
314 if (groupConfig.enabled) return await sock.sendMessage(chatId, { text: '⚠️ Anti-spam already enabled.', ...channelInfo }, { quoted: message });
315 if (!isBotAdmin && groupConfig.action !== 'warn') {
316 await sock.sendMessage(chatId, { text: `⚠️ Bot is not admin — kick/mute won't work until bot is made admin.`, ...channelInfo }, { quoted: message });
317 }
318 groupConfig.enabled = true;
319 await saveConfig(config);
320 return await sock.sendMessage(chatId, {
321 text: `✅ *Anti-spam enabled!*\nLimit: ${groupConfig.maxMessages} msgs in ${groupConfig.windowSeconds}s | Action: ${groupConfig.action.toUpperCase()}`,
322 ...channelInfo
323 }, { quoted: message });
324 }
325
326 if (action === 'off' || action === 'disable') {
327 if (!groupConfig.enabled) return await sock.sendMessage(chatId, { text: '⚠️ Anti-spam already disabled.', ...channelInfo }, { quoted: message });
328 groupConfig.enabled = false;
329 await saveConfig(config);
330 return await sock.sendMessage(chatId, { text: '❌ *Anti-spam disabled.*', ...channelInfo }, { quoted: message });
331 }
332
333 if (action === 'set') {
334 const maxMsgs = parseInt(args[1], 10);
335 const windowSec = parseInt(args[2], 10);
336 if (isNaN(maxMsgs) || isNaN(windowSec) || maxMsgs < 2 || windowSec < 1) {
337 return await sock.sendMessage(chatId, { text: '❌ Usage: `.antispam set <messages> <seconds>`\nExample: `.antispam set 5 10`', ...channelInfo }, { quoted: message });
338 }
339 groupConfig.maxMessages = maxMsgs;
340 groupConfig.windowSeconds = windowSec;
341 await saveConfig(config);
342 return await sock.sendMessage(chatId, { text: `✅ Limit: *${maxMsgs} msgs* in *${windowSec}s*`, ...channelInfo }, { quoted: message });
343 }

Callers

nothing calls this directly

Calls 2

loadConfigFunction · 0.85
saveConfigFunction · 0.70

Tested by

no test coverage detected