wolfyflutter

serialize

Oct 15th, 2025 (edited)
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { store, bot } from './../index.js'
  2. import { isJidGroup, isPnUser, getContentType, normalizeMessageContent } from 'baileys'
  3.  
  4.  
  5. export default async function (m) {
  6.     //let m = structuredClone(mOri)
  7.     m.message = normalizeMessageContent(m.message)
  8.     // m.text
  9.     const text =
  10.         // human
  11.         m.message?.conversation || // text
  12.         m.message?.extendedTextMessage?.text || // teks + dll
  13.         m.message?.imageMessage?.caption || // gambar
  14.         m.message?.videoMessage?.caption || // video
  15.  
  16.         /* bot */
  17.         m.message?.buttonsResponseMessage?.selectedDisplayText ||
  18.         null
  19.  
  20.     // m.key
  21.     const key = m.key
  22.  
  23.     // m.message
  24.     const message = m.message
  25.  
  26.     // m.pushName
  27.     const pushName = m.pushName
  28.  
  29.     // m.type
  30.     const type = getContentType(message)
  31.  
  32.     // m.chatId
  33.     const chatId = m.key.remoteJid
  34.  
  35.     // m.chatId
  36.     const here = m.key.remoteJid
  37.  
  38.     // m.senderId
  39.     const senderId = m.key.participant || (m.key.fromMe ? bot.id : m.key.senderLid)
  40.  
  41.  
  42.     // QUOTED
  43.     const qctx = m.message?.[type]?.contextInfo
  44.     const q_message = normalizeMessageContent(qctx?.quotedMessage)
  45.     let q = null
  46.  
  47.     if (q_message) {
  48.         // mapping pn to lid
  49.         if (isPnUser(qctx?.participant)) {
  50.             console.log('😲 mapping pn to lid')
  51.             qctx.participant = (await sock.signalRepository.lidMapping.pnToLIDFunc([qctx.participant]))?.[0]?.lid
  52.         }
  53.  
  54.         // m.q.text
  55.         const q_text =
  56.             // human
  57.             q_message?.conversation ||  // text
  58.             q_message?.extendedTextMessage?.text ||  // text + dll
  59.             q_message?.imageMessage?.caption || // gambar
  60.             q_message?.videoMessage?.caption || //video
  61.             // bot
  62.             q_message?.buttonsMessage?.contentText || null
  63.  
  64.         // m.q.pushName
  65.         const q_pushName = store.contacts_new.get(qctx?.participant)?.notify || null
  66.  
  67.         // m.q.type
  68.         const q_type = getContentType(q_message) || null
  69.  
  70.         // m.q.key
  71.         const q_key = {
  72.             remoteJid: q_message ? m.key.remoteJid : null,
  73.             id: qctx?.stanzaId || null,
  74.             participant: isJidGroup(m.key.remoteJid) ? qctx?.participant : null
  75.         }
  76.  
  77.         // m.q.sender
  78.         const q_senderId = qctx?.participant || null
  79.  
  80.         q = {
  81.             text: q_text,
  82.             pushName: q_pushName,
  83.             type: q_type,
  84.             key: q_key,
  85.             message: q_message,
  86.             senderId: q_senderId
  87.         }
  88.     }
  89.  
  90.     const result = {
  91.         key,
  92.         message,
  93.         pushName,
  94.         type,
  95.         text,
  96.         chatId,
  97.         here,
  98.         senderId,
  99.         q
  100.     }
  101.     return result
  102. }
  103.  
  104.  
Add Comment
Please, Sign In to add comment