-
Notifications
You must be signed in to change notification settings - Fork 825
/
jadibot.js
83 lines (78 loc) · 3.95 KB
/
jadibot.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
let { MessageType } = require('@adiwajshing/baileys')
const { is } = require('cheerio/lib/api/traversing')
let qrcode = require('qrcode')
let fs = require('fs')
let path = require('path')
if (global.conns instanceof Array) console.log()// for (let i of global.conns) global.conns[i] && global.conns[i].user ? global.conns[i].close().then(() => delete global.conns[id] && global.conns.splice(i, 1)).catch(global.conn.logger.error) : delete global.conns[i] && global.conns.splice(i, 1)
else global.conns = []
let handler = async (m, { conn, args, usedPrefix, command, isOwner }) => {
let package = JSON.parse(await fs.promises.readFile(path.join(__dirname, '../package.json')).catch(_ => '{}'))
if (!db.data.settings.jadibot) throw `This feature is not active\n${package.homepage ? package.homepage.url || package.homepage : '[unknown github url]'}`
let parent = args[0] && args[0] == 'plz' ? conn : global.conn
let auth = false
if ((args[0] && args[0] == 'plz') || global.conn.user.jid == conn.user.jid) {
let id = global.conns.length
let conn = new global.conn.constructor()
if (args[0] && args[0].length > 200) {
let json = Buffer.from(args[0], 'base64').toString('utf-8')
// global.conn.reply(m.isGroup ? m.sender : m.chat, json, m)
let obj = JSON.parse(json)
await conn.loadAuthInfo(obj)
auth = true
}
conn.on('qr', async qr => {
let scan = await parent.sendFile(m.chat, await qrcode.toDataURL(qr, { scale: 8 }), 'qrcode.png', 'Scan this QR to be a temporary bot\n\n1. Click the three dots in the upper right corner\n2. Tap WhatsApp Web\n3. Scan this QR \nQR Expires in 20 seconds', m)
setTimeout(() => {
parent.deleteMessage(m.chat, scan.key)
}, 30000)
})
conn.welcome = global.conn.welcome + ''
conn.bye = global.conn.bye + ''
conn.spromote = global.conn.spromote + ''
conn.sdemote = global.conn.sdemote + ''
conn.handler = global.conn.handler.bind(conn)
conn.onDelete = global.conn.onDelete.bind(conn)
conn.onParticipantsUpdate = global.conn.onParticipantsUpdate.bind(conn)
conn.onGroupUpdate = global.conn.onGroupUpdate.bind(conn)
conn.onCall = global.conn.onCall.bind(conn)
conn.on('chat-update', conn.handler)
conn.on('message-delete', conn.onDelete)
conn.on('group-participants-update', conn.onParticipantsUpdate)
conn.on('group-update', conn.onGroupUpdate)
conn.on('CB:action,,call', conn.onCall)
conn.regenerateQRIntervalMs = null
conn.connect().then(async ({ user }) => {
parent.reply(m.chat, 'Successfully connected with your WhatsApp.\n*NOTE: This is just a ride*\n' + JSON.stringify(user, null, 2), m)
if (auth) return
await parent.sendMessage(user.jid, `You can login without qr with the message below. to get the complete code, please send *${usedPrefix}getcode* to get the accurate code`, MessageType.extendedText)
parent.sendMessage(user.jid, `${usedPrefix + command} ${Buffer.from(JSON.stringify(conn.base64EncodedAuthInfo())).toString('base64')}`, MessageType.extendedText)
})
setTimeout(() => {
if (conn.user) return
conn.close()
let i = global.conns.indexOf(conn)
if (i < 0) return
delete global.conns[i]
global.conns.splice(i, 1)
}, 60000)
conn.on('close', () => {
setTimeout(async () => {
try {
if (conn.state != 'close') return
if (conn.user && conn.user.jid)
parent.sendMessage(conn.user.jid, `Connection disconnected...`, MessageType.extendedText)
let i = global.conns.indexOf(conn)
if (i < 0) return
delete global.conns[i]
global.conns.splice(i, 1)
} catch (e) { conn.logger.error(e) }
}, 30000)
})
global.conns.push(conn)
} else throw 'Can't make bot insidebot!\n\nhttps://wa.me/' + global.conn.user.jid.split`@`[0] + '?text=.jadibot'
}
handler.help = ['jadibot']
handler.tags = ['jadibot']
handler.command = /^jadibot$/i
handler.limit = true
module.exports = handler