Created
August 14, 2022 17:09
-
-
Save Iucasmaia/5a8ed63266df510cb0bc486da7b98e67 to your computer and use it in GitHub Desktop.
waitForMessage - made by maia - baileys
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sock.waitForMessage = async (from = false, timeout, max = false) => { | |
return new Promise((resolve) => { | |
var msgs = [] | |
let x = setTimeout(() => { | |
if (msgs.length < 1) { | |
resolve('idle') | |
} else { | |
resolve(msgs) | |
} | |
}, timeout); | |
sock.ev.on("messages.upsert", (chat) => { | |
if (chat && chat.type == 'notify') { | |
let mc = chat.messages[0] | |
if (mc.message && mc.key && mc.key.remoteJid != 'status@broadcast' && !mc.key.fromMe) { | |
mc.message = (getContentType(mc.message) === 'ephemeralMessage') ? mc.message.ephemeralMessage.message: mc.message; | |
mc.message = (getContentType(mc.message) === 'viewOnceMessage') ? mc.message.viewOnceMessage.message: mc.message; | |
if (max) { | |
if (msgs.length >= max) { | |
clearTimeout(x) | |
resolve(msgs) | |
} else { | |
if (from) { | |
if (mc.key.remoteJid == from) msgs.push(mc) | |
} else { | |
msgs.push(mc) | |
} | |
} | |
} else { | |
if (from) { | |
if (mc.key.remoteJid == from) msgs.push(mc) | |
} else { | |
msgs.push(mc) | |
} | |
} | |
} | |
} | |
}) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you helped me with this on discord months ago 😄