Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Multi device] Fix #158

Merged
merged 3 commits into from
Dec 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
node_modules
24 changes: 1 addition & 23 deletions config.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
20 changes: 10 additions & 10 deletions handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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())
})
})
13 changes: 5 additions & 8 deletions lib/print.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || ''}`)
Expand Down
189 changes: 137 additions & 52 deletions lib/simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ exports.makeWASocket = (...args) => {
conn.ev.on(eventName, on)
})
}


/**
* Send Media/File with Automatic Type Specifier
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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: '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 conn.relayMessage(
m.chat,
template.message,
{ messageId: template.key.id }
) */

/**
* cMod
Expand Down Expand Up @@ -646,19 +731,19 @@ 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)
if (m.msg && m.mtype == 'protocolMessage') conn.ev.emit('message.delete', m.msg.key)
} 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
}
}
5 changes: 3 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}


Expand Down
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down