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

Function handleGroupParticipantUpdate

lib/messageHandler.js:506–557  ·  view source on GitHub ↗
(sock, update)

Source from the content-addressed store, hash-verified

504 }
505}
506async function handleGroupParticipantUpdate(sock, update) {
507 try {
508 const { id, participants, action, author } = update;
509 // Invalidate antispam cache so admin changes take effect immediately
510 invalidateGroupCache(id);
511 if (!id.endsWith('@g.us'))
512 return;
513 printLog('info', `Group update: ${action} in ${id.split('@')[0]}`);
514 const botMode = await store.getBotMode();
515 const isPublicMode = botMode === 'public' || botMode === 'groups';
516 switch (action) {
517 case 'promote':
518 if (!isPublicMode)
519 return;
520 if (participants && participants.length > 0) {
521 const _participant = Array.isArray(participants) ? participants[0] : participants;
522 }
523 const handlePromotionEvent = (await import('../plugins/promote.js')).default?.handlePromotionEvent;
524 await handlePromotionEvent(sock, id, participants, author);
525 break;
526 case 'demote':
527 if (!isPublicMode)
528 return;
529 if (participants && participants.length > 0) {
530 const _participant = Array.isArray(participants) ? participants[0] : participants;
531 }
532 const handleDemotionEvent = (await import('../plugins/demote.js')).default?.handleDemotionEvent;
533 await handleDemotionEvent(sock, id, participants, author);
534 break;
535 case 'add':
536 if (participants && participants.length > 0) {
537 const _participant = Array.isArray(participants) ? participants[0] : participants;
538 }
539 const { handleJoinEvent } = await import('../plugins/welcome.js');
540 await handleJoinEvent(sock, id, participants);
541 break;
542 case 'remove':
543 if (participants && participants.length > 0) {
544 const _participant = Array.isArray(participants) ? participants[0] : participants;
545 }
546 const handleLeaveEvent = (await import('../plugins/goodbye.js')).default?.handleLeaveEvent;
547 await handleLeaveEvent(sock, id, participants);
548 break;
549 default:
550 printLog('warning', `Unhandled group action: ${action}`);
551 }
552 }
553 catch (error) {
554 printLog('error', `Group update error: ${error.message}`);
555 console.error(error.stack);
556 }
557}
558async function handleStatus(sock, status) {
559 try {
560 const { default: _autostatus } = await import('../plugins/autostatus.js');

Callers 2

startQasimDevFunction · 0.90

Calls 6

invalidateGroupCacheFunction · 0.90
printLogFunction · 0.90
handlePromotionEventFunction · 0.85
handleDemotionEventFunction · 0.85
handleJoinEventFunction · 0.85
handleLeaveEventFunction · 0.85

Tested by

no test coverage detected