From 744d4380184375ff6c1aa48127f5d50cfc79bdc2 Mon Sep 17 00:00:00 2001 From: zatu22 <74061098+zatu22@users.noreply.github.com> Date: Sun, 26 Dec 2021 11:39:17 +0100 Subject: [PATCH 1/3] Bug fix -Added missing node modules & fix -Fixed print message -Fixed global.owner error - New entry gitignore =MultiDevice is working now --- .gitignore | 1 + config.js | 24 +------ handler.js | 18 ++--- lib/print.js | 13 ++-- lib/simple.js | 189 ++++++++++++++++++++++++++++++++++++-------------- main.js | 5 +- package.json | 8 ++- 7 files changed, 163 insertions(+), 95 deletions(-) diff --git a/.gitignore b/.gitignore index a1c2a238a..a96d23c33 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* +node_modules diff --git a/config.js b/config.js index 25927f784..bc3690cd6 100644 --- a/config.js +++ b/config.js @@ -1,28 +1,6 @@ global.DeveloperMode = 'false' //true Or false global.linkGC = ['https://chat.whatsapp.com/Lb4Emjih98rBiCZiZoS2eM', 'https://chat.whatsapp.com/FrluVyY5kBRIhY6yKfH4DI'] -global.Owner = { - // use the phone number with the country code, for example Indonesia '62' America '1' etc - '6281390658325': { // put your number here - name: 'Owner Metro Bot/Creator games-wabot', - isDev: true, // if true this number will send if bot have bug and developer mode true - isReport: true, // if true this number will send if user use command /report or /join - isCreator: true // if true this number will send if user use command /owner or /creator - }, - '6282256115584': { // put your number here - name: 'Dave', - isDev: false, // if true this number will send if bot have bug and developer mode true - isReport: true, // if true this number will send if user use command /report or /join - isCreator: false // if true this number will send if user use command /owner or /creator - }, - '60199782326': { - name: 'Adiixyz', - isReport: true, // if true this number will send if user use command /report or /join - }, - '6285713964963': { - isReport: true - }, - '13479805233': {} // ignore if you don't want anything, like name dll -} +global.owner = ['6281390658325', '6282256115584', '60199782326', '6285713964963','13479805233'] global.mods = ['13479805233'] // Want some help? global.prems = [] // Premium user has unlimited limit global.APIs = { // API Prefix diff --git a/handler.js b/handler.js index 3ec83953c..bf521078f 100644 --- a/handler.js +++ b/handler.js @@ -231,8 +231,8 @@ module.exports = { let participants = (m.isGroup ? groupMetadata.participants : []) || [] let user = (m.isGroup ? participants.find(u => conn.decodeJid(u.id) === m.sender) : {}) || {} // User Data let bot = (m.isGroup ? participants.find(u => conn.decodeJid(u.id) == this.user.jid) : {}) || {} // Your Data - let isAdmin = user && user.admin || false // Is User Admin? - let isBotAdmin = bot && bot.admin || false // Are you Admin? + let isAdmin = user?.admin || user?.superadmin || false // Is User Admin? + let isBotAdmin = bot?.admin || bot?.superadmin || false // Are you Admin? for (let name in global.plugins) { let plugin = global.plugins[name] if (!plugin) continue @@ -408,7 +408,7 @@ module.exports = { let stat if (m.plugin) { - let now = + new Date + let now = +new Date if (m.plugin in stats) { stat = stats[m.plugin] if (!isNumber(stat.total)) stat.total = 1 @@ -430,11 +430,11 @@ module.exports = { } } - // try { - // require('./lib/print')(m, this) - // } catch (e) { - // console.log(m, m.quoted, e) - // } + try { + require('./lib/print')(m, this) + } catch (e) { + console.log(m, m.quoted, e) + } if (opts['autoread']) await this.chatRead(m.chat, m.isGroup ? m.sender : undefined, m.id || m.key.id).catch(() => { }) let quequeIndex = this.msgqueque.indexOf(m.id || m.key.id) if (opts['queque'] && m.text && quequeIndex !== -1) this.msgqueque.splice(quequeIndex, 1) @@ -473,7 +473,7 @@ module.exports = { case 'demote': if (!text) text = (chat.sDemote || this.sdemote || conn.sdemote || '@user ```is no longer Admin```') text = text.replace('@user', '@' + participants[0].split('@')[0]) - if (chat.detect) this.sendMessage(id, text, MessageType.extendedText, { + if (chat.detect) this.sendMessage(id, { text: text }, { contextInfo: { mentionedJid: this.parseMention(text) } diff --git a/lib/print.js b/lib/print.js index ed616b7c2..4b9c1f64b 100644 --- a/lib/print.js +++ b/lib/print.js @@ -70,14 +70,11 @@ ${chalk.green('%s')} ${chalk.yellow('%s%s')} ${chalk.blueBright('to')} ${chalk.g if (m.mentionedJid) for (let user of m.mentionedJid) log = log.replace('@' + user.split`@`[0], chalk.blueBright('@' + await conn.getName(user))) console.log(m.error != null ? chalk.red(log) : m.isCommand ? chalk.yellow(log) : log) } - let messageStubParameters = '' - if (m.messageStubParameters) { - for (let jid of m.messageStubParameters) { - let name = await conn.getName(jid) - messageStubParameters += chalk.gray(PhoneNumber('+' + jid.replace('@s.whatsapp.net', '')).getNumber('international') + (name ? ' ~' + name : '') + m.messageStubParameters.indexOf(jid) > 0 && m.messageStubParameters.indexOf(jid) !== (m.messageStubParameters.length - 1) ? ', ' : '') - } - console.log(messageStubParameters) - } + if (m.messageStubParameters) console.log(m.messageStubParameters.map(jid => { + jid = conn.decodeJid(jid) + let name = conn.getName(jid) + return chalk.gray(PhoneNumber('+' + jid.replace('@s.whatsapp.net', '')).getNumber('international') + (name ? ' ~' + name : '')) + }).join(', ')) if (/document/i.test(m.mtype)) console.log(`๐Ÿ“„ ${m.msg.filename || m.msg.displayName || 'Document'}`) else if (/ContactsArray/i.test(m.mtype)) console.log(`๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ ${' ' || ''}`) else if (/contact/i.test(m.mtype)) console.log(`๐Ÿ‘จ ${m.msg.displayName || ''}`) diff --git a/lib/simple.js b/lib/simple.js index 5f9e008c4..81e5e0c81 100644 --- a/lib/simple.js +++ b/lib/simple.js @@ -155,6 +155,7 @@ exports.makeWASocket = (...args) => { conn.ev.on(eventName, on) }) } + /** * Send Media/File with Automatic Type Specifier @@ -238,7 +239,9 @@ END:VCARD conn.reply = (jid, text = '', quoted, options) => { return Buffer.isBuffer(text) ? this.sendFile(jid, text, 'file', '', quoted, false, options) : conn.sendMessage(jid, { ...options, text }, { quoted, ...options }) } - + conn.fakeReply = (jid, text = '', fakeJid = conn.user.jid, fakeText = '', fakeGroupJid, options) => { + return this.reply(jid, text, { key: { fromMe: fakeJid == this.user.jid, participant: fakeJid, ...(fakeGroupJid ? { remoteJid: fakeGroupJid } : {}) }, message: { conversation: fakeText }, ...options }) + } /** * send Button * @param {String} jid @@ -271,8 +274,90 @@ END:VCARD ...options }) } - // const { generateWAMessageFromContent, proto } = require('@adiwajshing/baileys-md') - // const template = generateWAMessageFromContent(m.chat, proto.Message.fromObject({ + conn.sendHButt = async (jid, content, distek, link, discall, number, retek, id,quoted) => { + let template = generateWAMessageFromContent(jid, proto.Message.fromObject({ + templateMessage: { + hydratedTemplate: { + hydratedContentText: content, + hydratedButtons: [{ + urlButton: { + displayText: distek, + url: link + } + }, { + callButton: { + displayText: discall, + phoneNumber: number + } + }, + { + quickReplyButton: { + displayText:retek, + id: id + } + } + ] + } + } + }), { userJid: conn.user.jid, quoted: quoted}); + return await conn.relayMessage( + jid, + template.message, + { messageId: template.key.id } + ) + } + conn.sendButtonLoc= async (jid, buffer, content, footer, button1, row1, quoted, options = {}) => { + let buttons = [{buttonId: row1, buttonText: {displayText: button1}, type: 1}] + let buttonMessage = { + location: { jpegThumbnail: buffer }, + caption: content, + footer: footer, + buttons: buttons, + headerType: 6 +} + return await conn.sendMessage(jid, buttonMessage, { + quoted, + upload: conn.waUploadToServer, + ...options + }) + } + conn.send2ButtonLoc= async (jid, buffer, content, footer, button1, row1, button2, row2, quoted, options = {}) => { + let buttons = [{buttonId: row1, buttonText: {displayText: button1}, type: 1}, + { buttonId: row2, buttonText: { displayText: button2 }, type: 1 }] + let buttonMessage = { + location: { jpegThumbnail: buffer }, + caption: content, + footer: footer, + buttons: buttons, + headerType: 6 +} + return await conn.sendMessage(jid, buttonMessage, { + quoted, + upload: conn.waUploadToServer, + ...options + }) + } + conn.send3ButtonLoc= async (jid, buffer, content, footer, button1, row1, button2, row2, quoted, options = {}) => { + let buttons = [{buttonId: row1, buttonText: {displayText: button1}, type: 1}, + { buttonId: row2, buttonText: { displayText: button2 }, type: 1 }, + { buttonId: row3, buttonText: { displayText: button3 }, type: 1 } + ] + let buttonMessage = { + location: { jpegThumbnail: buffer }, + caption: content, + footer: footer, + buttons: buttons, + headerType: 6 +} + return await conn.sendMessage(jid, buttonMessage, { + quoted, + upload: conn.waUploadToServer, + ...options + }) + } + + /* const { generateWAMessageFromContent, proto } = require('@adiwajshing/baileys-md') + const template = generateWAMessageFromContent(m.chat, proto.Message.fromObject({ // templateMessage: { // hydratedTemplate: { // hydratedContentText: 'Testing', @@ -303,51 +388,51 @@ END:VCARD // template.message, // { messageId: template.key.id } // ) - // templateMessage: { - // hydratedTemplate: { - // hydratedContentText: text.trim(), - // hydratedButtons: [{ - // urlButton: { - // displayText: 'RestApi', - // url: 'https://api.dhamzxploit.my.id' - // } - - // }, - // { - // callButton: { - // displayText: 'Call Me', - // phoneNumber: '+6285294959195' - // } - // }, - // { - // quickReplyButton: { - // displayText: 'BUTTON 1 ', - // id: '.ping' - // } - - // }, - // { - // quickReplyButton: { - // displayText: 'BUTTON 2', - // id: '.ping' - // } - - // }, - // { - // quickReplyButton: { - // displayText: 'BUTTON 3', - // id: '.ping' - // } - - // }] - // } - // } - // }), { userJid: m.sender, quoted: m }); - // return await conn.relayMessage( - // m.chat, - // template.message, - // { messageId: template.key.id } - // ) + templateMessage: { + hydratedTemplate: { + hydratedContentText: text.trim(), + hydratedButtons: [{ + urlButton: { + displayText: 'Source Code', + url: 'https://github.com/adulalhy/nana-md' + } + + }, + { + callButton: { + displayText: 'Call Owner', + phoneNumber: '+62' + } + }, + { + quickReplyButton: { + displayText: 'Owner', + id: '.owner' + } + + }, + { + quickReplyButton: { + displayText: 'BUTTON 2', + id: '.ping' + } + + }, + { + quickReplyButton: { + displayText: 'BUTTON 3', + id: '.ping' + } + + }] + } + } + }), { userJid: m.sender, quoted: m }); + return conn.relayMessage( + m.chat, + template.message, + { messageId: template.key.id } + ) */ /** * cMod @@ -646,7 +731,7 @@ exports.smsg = (conn, m, hasParent) => { */ m.delete = () => conn.sendMessage(m.chat, { delete: m.key }) - try { + /* try { conn.saveName(m.sender, m.name) conn.pushMessage(m) if (m.isGroup) conn.saveName(m.chat) @@ -654,11 +739,11 @@ exports.smsg = (conn, m, hasParent) => { } catch (e) { console.error(e) } - return m -} + return m*/ +} exports.logic = (check, inp, out) => { if (inp.length !== out.length) throw new Error('Input and Output must have same length') for (let i in inp) if (util.isDeepStrictEqual(check, inp[i])) return out[i] return null -} \ No newline at end of file +} diff --git a/main.js b/main.js index 431197571..196ecbd6c 100644 --- a/main.js +++ b/main.js @@ -81,15 +81,16 @@ if (!opts['test']) { if (opts['autocleartmp'] && (global.support || {}).find) (tmp = [os.tmpdir(), 'tmp'], tmp.forEach(filename => cp.spawn('find', [filename, '-amin', '3', '-type', 'f', '-delete']))) }, 30 * 1000) } +if (opts['server']) require('./server')(global.conn, PORT) async function connectionUpdate(update) { const { connection, lastDisconnect } = update global.timestamp.connect = new Date if (lastDisconnect && lastDisconnect.error && lastDisconnect.error.output && lastDisconnect.error.output.statusCode !== DisconnectReason.loggedOut && conn.ws.readyState !== WebSocket.CONNECTING) { - console.log(global.reloadHandler(true)) + // console.log(global.reloadHandler(true)) } if (global.db.data == null) await loadDatabase() - console.log(JSON.stringify(update, null, 4)) + // console.log(JSON.stringify(update, null, 4)) } diff --git a/package.json b/package.json index d5c443d0f..ab6bd21fb 100644 --- a/package.json +++ b/package.json @@ -37,21 +37,27 @@ "license": "GPL-3.0-or-later", "dependencies": { "@adiwajshing/baileys-md": "github:adiwajshing/baileys#multi-device", - "awesome-phonenumber": "^2.64.0", + "awesome-phonenumber": "^2.58.0", "axios": "^0.24.0", + "brainly-scraper-v2": "^2.0.9", "cfonts": "^2.10.0", "chalk": "^4.1.2", "cheerio": "^1.0.0-rc.10", "file-type": "^16.5.3", + "fluent-ffmpeg": "^2.1.2", "form-data": "^4.0.0", "g-i-s": "^2.1.6", "google-it": "^1.6.2", "human-readable": "^0.2.1", + "imgbb-uploader": "^1.3.5", "jsdom": "^18.1.1", "lodash": "^4.17.21", "lowdb": "^2.1.0", + "moment-timezone": "^0.5.34", "mongoose": "^6.0.14", "node-fetch": "^2.6.6", + "node-gtts": "^2.0.2", + "node-os-utils": "^1.3.5", "node-webpmux": "^3.1.0", "nodemon": "^2.0.15", "perf_hooks": "^0.0.1", From fc6506dde90f4ea0f8cff14e0f20571a96417a5e Mon Sep 17 00:00:00 2001 From: zatu22 <74061098+zatu22@users.noreply.github.com> Date: Sun, 26 Dec 2021 11:42:11 +0100 Subject: [PATCH 2/3] Update simple.js --- lib/simple.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/simple.js b/lib/simple.js index 81e5e0c81..d3c510ced 100644 --- a/lib/simple.js +++ b/lib/simple.js @@ -393,21 +393,21 @@ END:VCARD hydratedContentText: text.trim(), hydratedButtons: [{ urlButton: { - displayText: 'Source Code', - url: 'https://github.com/adulalhy/nana-md' + displayText: 'RestApi', + url: 'https://api.dhamzxploit.my.id' } }, { callButton: { - displayText: 'Call Owner', - phoneNumber: '+62' + displayText: 'Call Me', + phoneNumber: '+6285294959195' } }, { quickReplyButton: { - displayText: 'Owner', - id: '.owner' + displayText: 'BUTTON 1', + id: '..ping' } }, From 96ffeee4945a996820ddb9e97498842f454328a5 Mon Sep 17 00:00:00 2001 From: zatu22 <74061098+zatu22@users.noreply.github.com> Date: Sun, 26 Dec 2021 11:51:26 +0100 Subject: [PATCH 3/3] Update handler.js --- handler.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/handler.js b/handler.js index bf521078f..3591deac4 100644 --- a/handler.js +++ b/handler.js @@ -231,8 +231,8 @@ module.exports = { let participants = (m.isGroup ? groupMetadata.participants : []) || [] let user = (m.isGroup ? participants.find(u => conn.decodeJid(u.id) === m.sender) : {}) || {} // User Data let bot = (m.isGroup ? participants.find(u => conn.decodeJid(u.id) == this.user.jid) : {}) || {} // Your Data - let isAdmin = user?.admin || user?.superadmin || false // Is User Admin? - let isBotAdmin = bot?.admin || bot?.superadmin || false // Are you Admin? + let isAdmin = user.isAdmin || user.isSuperAdmin || false // Is User Admin? + let isBotAdmin = bot.isAdmin || bot.isSuperAdmin || false // Are you Admin? for (let name in global.plugins) { let plugin = global.plugins[name] if (!plugin) continue @@ -523,4 +523,4 @@ fs.watchFile(file, () => { console.log(chalk.redBright("Update 'handler.js'")) delete require.cache[file] if (global.reloadHandler) console.log(global.reloadHandler()) -}) \ No newline at end of file +})