Advertisement
DigitalCliques

Remover não leitores de grupos!

Jun 3rd, 2025
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 1.89 KB | Source Code | 0 0
  1. window.WPP.getRemainingParticipants = async function(serializedMsgId) {
  2.   // 1) obtém o ACKInfo (quem recebeu e leu)
  3.   const ackInfo = await window.WPP.chat.getMessageACK(serializedMsgId);
  4.   const respondedSet = new Set(ackInfo.participants.map(p => p.id));
  5.  
  6.   // 2) extrai groupId e senderId do serialized
  7.   const parts    = serializedMsgId.split('_');
  8.   const groupId  = parts[1];  
  9.   const senderId = parts[3];  
  10.  
  11.   // 3) coleta todos os participantes do grupo
  12.   const participants = await window.WPP.group.getParticipants(groupId);
  13.   const allIds = [];
  14.   for (let p of participants) {
  15.     if (typeof p === 'string') {
  16.       allIds.push(p);
  17.     } else if (p.id && p.id._serialized) {
  18.       allIds.push(p.id._serialized);
  19.     } else if (p._serialized) {
  20.       allIds.push(p._serialized);
  21.     }
  22.   }
  23.  
  24.   // 4) filtra quem não respondeu (nem recebeu nem leu) e não é remetente
  25.   const toRemove = allIds.filter(id => !respondedSet.has(id) && id !== senderId);
  26.  
  27.   // 5) tenta remover, tratando erros de permissão
  28.   let actuallyRemoved = [];
  29.   if (toRemove.length) {
  30.     try {
  31.       await window.WPP.group.removeParticipants(groupId, toRemove);
  32.       actuallyRemoved = toRemove;
  33.     } catch (err) {
  34.       const msg = err?.message || err;
  35.       if (msg.includes("not admin")) {
  36.         console.warn(`⚠️ Não sou admin em ${groupId}, não foi possível remover participantes.`);
  37.       } else {
  38.         console.error("❌ Erro ao remover participantes:", err);
  39.       }
  40.       // Em caso de erro, não repassa a exception para não poluir o console
  41.     }
  42.   }
  43.  
  44.   // 6) retorna a lista de IDs que de fato removemos (ou vazia)
  45.   return actuallyRemoved;
  46. };
  47.  
  48. // Exemplo de uso:
  49. (async () => {
  50.   const serialized = "[email protected]_3EB060039007B34BCBEEAB";
  51.   const removed = await window.WPP.getRemainingParticipants(serialized);
  52.   console.log('🔍 IDs removidos:', removed);
  53. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement