Reorganize este código JS mantendo a lógica, mas melhorando a estrutura: * @param {}…
- User
Reorganize este código JS mantendo a lógica, mas melhorando a estrutura:
* @param {*} quoted * @param {*} options * @returns */ client.sendText = (jid, text, quoted = '', options) => client.sendMessage(jid, { text: text, ...options }, { quoted, ...options }) /** * * @param {*} jid * @param {*} path * @param {*} caption * @param {*} quoted * @param {*} options * @returns */ client.sendImage = async (jid, path, caption = '', quoted = '', options) => { let buffer = Buffer.isBuffer(path) ? path : /^data:.*?\/.*?;base64,/i.test(path) ? Buffer.from(path.split`,`[1], 'base64') : /^https?:\/\//.test(path) ? await (await getBuffer(path)) : fs.existsSync(path) ? fs.readFileSync(path) : Buffer.alloc(0) return await client.sendMessage(jid, { image: buffer, caption: caption, ...options }, { quoted }) } /** * * @param {*} jid * @param {*} path * @param {*} caption * @param {*} quoted * @param {*} options * @returns */ client.sendVideo = async (jid, path, caption = '', quoted = '', gif = false, options) => { let buffer = Buffer.isBuffer(path) ? path : /^data:.*?\/.*?;base64,/i.test(path) ? Buffer.from(path.split`,`[1], 'base64') : /^https?:\/\//.test(path) ? await (await getBuffer(path)) : fs.existsSync(path) ? fs.readFileSync(path) : Buffer.alloc(0) return await client.sendMessage(jid, { video: buffer, caption: caption, gifPlayback: gif, ...options }, { quoted }) } /** * * @param {*} jid * @param {*} path * @param {*} quoted * @param {*} mime * @param {*} options * @returns */ client.sendAudio = async (jid, path, quoted = '', ptt = false, options) => { let buffer = Buffer.isBuffer(path) ? path : /^data:.*?\/.*?;base64,/i.test(path) ? Buffer.from(path.split`,`[1], 'base64') : /^https?:\/\//.test(path) ? await (await getBuffer(path)) : fs.existsSync(path) ? fs.readFileSync(path) : Buffer.alloc(0) - Assistant