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

Function handler

plugins/localbot.ts:357–419  ·  view source on GitHub ↗
(sock: any, message: any, args: any[], context: BotContext)

Source from the content-addressed store, hash-verified

355 usage: '.localbot on/off\n.localbot <message>',
356
357 async handler(sock: any, message: any, args: any[], context: BotContext) {
358 const { chatId, channelInfo, senderId } = context;
359 const senderName = (message.pushName || senderId.split('@')[0] || 'there').split(' ')[0];
360 const sub = args[0]?.toLowerCase();
361
362 if (sub === 'on') {
363 chatState.set(chatId, { enabled: true, lastActivity: Date.now() });
364 return await sock.sendMessage(chatId, {
365 text: `🤖 *Local Bot Activated!*\n\n` +
366 `I'm now listening in this chat.\n` +
367 `Just type anything and I'll respond!\n\n` +
368 `_Fully offline • No API • Instant replies_\n\n` +
369 `Type \`.localbot off\` to deactivate.`,
370 ...channelInfo
371 }, { quoted: message });
372 }
373
374 if (sub === 'off') {
375 chatState.delete(chatId);
376 return await sock.sendMessage(chatId, {
377 text: `🤖 Local Bot *deactivated*.\nUse \`.localbot on\` to reactivate.`,
378 ...channelInfo
379 }, { quoted: message });
380 }
381
382 if (sub === 'status') {
383 const state = chatState.get(chatId);
384 return await sock.sendMessage(chatId, {
385 text: `🤖 Local Bot: ${state?.enabled ? '🟢 *Active*' : '🔴 *Inactive*'}`,
386 ...channelInfo
387 }, { quoted: message });
388 }
389
390 const userText = args.join(' ').trim();
391 if (!userText) {
392 const state = chatState.get(chatId);
393 return await sock.sendMessage(chatId, {
394 text: `🤖 *MEGA MD Local Bot*\n\n` +
395 `_Zero API • Fully Offline • Instant_\n\n` +
396 `*Chat directly:*\n` +
397 `\`.localbot hello\`\n` +
398 `\`.localbot tell me a joke\`\n` +
399 `\`.localbot motivate me\`\n` +
400 `\`.localbot what time is it\`\n` +
401 `\`.localbot 25 * 4\`\n\n` +
402 `*Auto-reply mode:*\n` +
403 `\`.localbot on\` — respond to ALL messages in this chat\n` +
404 `\`.localbot off\` — stop\n\n` +
405 `*Status:* ${state?.enabled ? '🟢 Active' : '🔴 Inactive'}`,
406 ...channelInfo
407 }, { quoted: message });
408 }
409
410 await sock.presenceSubscribe(chatId);
411 await sock.sendPresenceUpdate('composing', chatId);
412 await new Promise(r => setTimeout(r, 600 + Math.random() * 800));
413 await sock.sendPresenceUpdate('paused', chatId);
414

Callers

nothing calls this directly

Calls 1

getResponseFunction · 0.70

Tested by

no test coverage detected