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

Function handler

plugins/chatbot.js:277–335  ·  view source on GitHub ↗
(sock, message, args, context)

Source from the content-addressed store, hash-verified

275 groupOnly: true,
276 adminOnly: true,
277 async handler(sock, message, args, context) {
278 const chatId = context.chatId || message.key.remoteJid;
279 const match = args.join(' ').toLowerCase();
280 if (!match) {
281 await showTyping(sock, chatId);
282 return sock.sendMessage(chatId, {
283 text: `*🤖 CHATBOT SETUP*\n\n` +
284 `*Storage:* ${HAS_DB ? 'Database' : 'File System'}\n` +
285 `*APIs:* ${API_ENDPOINTS.length} endpoints with fallback\n\n` +
286 `*Commands:*\n` +
287 `• \`.chatbot on\` - Enable chatbot\n` +
288 `• \`.chatbot off\` - Disable chatbot\n\n` +
289 `*How it works:*\n` +
290 `When enabled, bot responds when mentioned or replied to.\n\n` +
291 `*Features:*\n` +
292 `• Natural English conversations\n` +
293 `• Remembers context\n` +
294 `• Personality-based replies\n` +
295 `• Auto fallback if API fails`,
296 quoted: message
297 });
298 }
299 const data = await loadUserGroupData();
300 if (match === 'on') {
301 await showTyping(sock, chatId);
302 if (data.chatbot[chatId]) {
303 return sock.sendMessage(chatId, {
304 text: '⚠️ *Chatbot is already enabled for this group*',
305 quoted: message
306 });
307 }
308 data.chatbot[chatId] = true;
309 await saveUserGroupData(data);
310 return sock.sendMessage(chatId, {
311 text: '✅ *Chatbot enabled!*\n\nMention me or reply to my messages to chat.',
312 quoted: message
313 });
314 }
315 if (match === 'off') {
316 await showTyping(sock, chatId);
317 if (!data.chatbot[chatId]) {
318 return sock.sendMessage(chatId, {
319 text: '⚠️ *Chatbot is already disabled for this group*',
320 quoted: message
321 });
322 }
323 delete data.chatbot[chatId];
324 await saveUserGroupData(data);
325 return sock.sendMessage(chatId, {
326 text: '❌ *Chatbot disabled!*\n\nI will no longer respond to mentions.',
327 quoted: message
328 });
329 }
330 await showTyping(sock, chatId);
331 return sock.sendMessage(chatId, {
332 text: '❌ *Invalid command*\n\nUse: `.chatbot on/off`',
333 quoted: message
334 });

Callers

nothing calls this directly

Calls 3

showTypingFunction · 0.85
loadUserGroupDataFunction · 0.70
saveUserGroupDataFunction · 0.70

Tested by

no test coverage detected