forked from Tanmyname/Shizuka-V1.2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjadibot.js
257 lines (240 loc) · 9.45 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
const { modul } = require('./module');
const { baileys, boom, chalk, fs, figlet, FileType, process, PhoneNumber } = modul;
const { Boom } = boom
const path = require('path');
const { default: makeWaSocket, useMultiFileAuthState, DisconnectReason, fetchLatestBaileysVersion, generateForwardMessageContent, generateWAMessage, prepareWAMessageMedia, generateWAMessageFromContent, generateMessageID, downloadContentFromMessage, makeInMemoryStore, jidDecode, proto, makeCacheableSignalKeyStore } = baileys
const { color, bgcolor } = require('./lib/color')
const log = (pino = require("pino"));
const qrcode = require('qrcode');
const rimraf = require("rimraf");
let Pino = require("pino")
const { imageToWebp, videoToWebp, writeExifImg, writeExifVid } = require('./lib/exif')
const { smsg, isUrl, generateMessageTag, getBuffer, getSizeMedia, fetchJson, await, sleep, reSize } = require('./lib/myfunc')
const owner = JSON.parse(fs.readFileSync('./database/owner.json').toString())
const store = makeInMemoryStore({ logger: pino().child({ level: 'silent', stream: 'store' }) })
let NodeCache = require("node-cache")
let msgRetryCounterCache = new NodeCache()
if (global.conns instanceof Array) console.log()
else global.conns = []
const jadibot = async (Fernazer, text, m) => {
const { sendImage, sendMessage } = Fernazer;
//sendMessage(from, 'tesss');
const { reply, sender } = m;
const { state, saveCreds } = await useMultiFileAuthState(path.join(__dirname, `./database/rentbot/${sender}`), log({ level: "silent" }));
try {
async function start() {
let { version, isLatest } = await fetchLatestBaileysVersion();
const config = {
logger: Pino({ level: "fatal" }).child({ level: "fatal" }),
printQRInTerminal: false,
mobile: false,
auth: {
creds: state.creds,
keys: makeCacheableSignalKeyStore(state.keys, Pino({ level: "fatal" }).child({ level: "fatal" })),
},
browser: [ 'Mac OS', 'Safari', '10.15.7' ],
markOnlineOnConnect: true,
generateHighQualityLinkPreview: true,
msgRetryCounterCache,
defaultQueryTimeoutMs: undefined
}
let simple = require('./index')
if (!Fernazer.authState.creds.registered) {
setTimeout(async () => {
let phoneNumber = `${text}`
console.log(chalk.red.bold(`[ Jadibot ] -> (+${phoneNumber})`))
let code = await Fernazer.requestPairingCode(phoneNumber)
let hasilcode = code?.match(/.{1,4}/g)?.join("-") || code
global.codepairing = `${hasilcode}`
}, 3000)
}
Fernazer.ws.on('CB:Blocklist', json => {
if (blocked.length > 2) return
for (let i of json[1].blocklist) {
blocked.push(i.replace('c.us','s.whatsapp.net'))}})
Fernazer.ws.on('CB:call', async (json) => {
const callerId = json.content[0].attrs['call-creator']
const idCall = json.content[0].attrs['call-id']
const Id = json.attrs.id
const T = json.attrs.t
Fernazer.sendNode({
tag: 'call',
attrs: {
from: '[email protected]',
id: Id,
t: T
},
content: [
{
tag: 'reject',
attrs: {
'call-creator': callerId,
'call-id': idCall,
count: '0'
},
content: null
}
]
})
if (json.content[0].tag == 'offer') {
let qutsnya = await Fernazer.sendContact(callerId, owner)
await Fernazer.sendMessage(callerId, { text: `Sistem Otomatis Block!!!\nJangan Menelpon Bot!!!\nSilahkan Hubungi Owner Untuk Dibuka!!!`}, { quoted : qutsnya })
await sleep(8000)
await Fernazer.updateBlockStatus(callerId, "block")
}
})
Fernazer.ev.on('messages.upsert', async chatUpdate => {
try {
kay = chatUpdate.messages[0]
if (!kay.message) return
kay.message = (Object.keys(kay.message)[0] === 'ephemeralMessage') ? kay.message.ephemeralMessage.message : kay.message
if (kay.key && kay.key.remoteJid === 'status@broadcast') return
if (!Fernazer.public && !kay.key.fromMe && chatUpdate.type === 'notify') return
if (kay.key.id.startsWith('BAE5') && kay.key.id.length === 16) return
m = smsg(Fernazer, kay, store)
require('./FLIXBOT.js')(Fernazer, m, chatUpdate, store)
} catch (err) {
console.log(err)}
})
Fernazer.public = true
store.bind(Fernazer.ev);
Fernazer.ev.on("creds.update", saveCreds);
Fernazer.ev.on("connection.update", async up => {
const { lastDisconnect, connection } = up;
if (connection == "connecting") return
if (connection){
if (connection != "connecting") console.log("Connecting to jadibot..")
}
/*console.log(up)
if (up.qr) await sendImage(from, await qrcode.toDataURL(up.qr,{scale : 8}), 'Scan QR ini untuk jadi bot sementara\n\n1. Klik titik tiga di pojok kanan atas\n2. Ketuk WhatsApp Web\n3. Scan QR ini \nQR Expired dalam 30 detik\nBot akan Mengirim lagi Jika Qr Expire', m)*/
if (connection == "open") {
Fernazer.id = Fernazer.decodeJid(Fernazer.user.id)
Fernazer.time = Date.now()
global.conns.push(Fernazer)
await m.reply(`*Connected to Whatsapp - Bot*\n\n*User :*\n _*× id : ${Fernazer.decodeJid(Fernazer.user.id)}*_`)
user = `${Fernazer.decodeJid(Fernazer.user.id)}`
txt = `*Terdeteksi menumpang Jadibot*\n\n _ User : @${user.split("@")[0]}_`
sendMessage(`[email protected]`,{text: txt, mentions : [user]})
}
if (connection === 'close') {
let reason = new Boom(lastDisconnect?.error)?.output.statusCode
if (reason === DisconnectReason.badSession) {
console.log(`Bad Session File, Please Delete Session and Scan Again`); Fernazer.logout(); }
else if (reason === DisconnectReason.connectionClosed) {
console.log("Connection closed, reconnecting...."); start(); }
else if (reason === DisconnectReason.connectionLost) {
console.log("Connection Lost from Server, reconnecting..."); start(); }
else if (reason === DisconnectReason.connectionReplaced) {
console.log("Connection Replaced, Another New Session Opened, Please Close Current Session First"); Fernazer.logout(); }
else if (reason === DisconnectReason.loggedOut) {
console.log(`Fernazerce Logged Out, Please Scan Again And Run.`); Fernazer.logout(); }
else if (reason === DisconnectReason.restartRequired) {
console.log("Restart Required, Restarting..."); start(); }
else if (reason === DisconnectReason.timedOut) {
console.log("Connection TimedOut, Reconnecting..."); start(); }
else Fernazer.end(`Unknown DisconnectReason: ${reason}|${connection}`)
}
})
Fernazer.decodeJid = (jid) => {
if (!jid) return jid
if (/:\d+@/gi.test(jid)) {
let decode = jidDecode(jid) || {}
return decode.user && decode.server && decode.user + '@' + decode.server || jid
} else return jid
}
Fernazer.ev.on('contacts.update', update => {
for (let contact of update) {
let id = Fernazer.decodeJid(contact.id)
if (store && store.contacts) store.contacts[id] = { id, name: contact.notify }
}
})
Fernazer.getName = (jid, withoutContact = false) => {
id = Fernazer.decodeJid(jid)
withoutContact = Fernazer.withoutContact || withoutContact
let v
if (id.endsWith("@g.us")) return new Promise(async (resolve) => {
v = store.contacts[id] || {}
if (!(v.name || v.subject)) v = Fernazer.groupMetadata(id) || {}
resolve(v.name || v.subject || PhoneNumber('+' + id.replace('@s.whatsapp.net', '')).getNumber('international'))
})
else v = id === '[email protected]' ? {
id,
name: 'WhatsApp'
} : id === Fernazer.decodeJid(Fernazer.user.id) ?
Fernazer.user :
(store.contacts[id] || {})
return (withoutContact ? '' : v.name) || v.subject || v.verifiedName || PhoneNumber('+' + jid.replace('@s.whatsapp.net', '')).getNumber('international')
}
Fernazer.parseMention = (text = '') => {
return [...text.matchAll(/@([0-9]{5,16}|0)/g)].map(v => v[1] + '@s.whatsapp.net')
}
Fernazer.sendContact = async (jid, kon, quoted = '', opts = {}) => {
let list = []
for (let i of kon) {
list.push({
displayName: await Fernazer.getName(i + '@s.whatsapp.net'),
vcard: `BEGIN:VCARD\n
VERSION:3.0\n
N:${await Fernazer.getName(i + '@s.whatsapp.net')}\n
FN:${await Fernazer.getName(i + '@s.whatsapp.net')}\n
item1.TEL;waid=${i}:${i}\n
item1.X-ABLabel:Ponsel\n
item2.EMAIL;type=INTERNET:[email protected]\n
item2.X-ABLabel:Email\n
item3.URL:https://bit.ly/39Ivus6\n
item3.X-ABLabel:YouTube\n
item4.ADR:;;Indonesia;;;;\n
item4.X-ABLabel:Region\n
END:VCARD`
})
}
Fernazer.sendMessage(jid, { contacts: { displayName: `${list.length} Kontak`, contacts: list }, ...opts }, { quoted })
}
Fernazer.setStatus = (status) => {
Fernazer.query({
tag: 'iq',
attrs: {
to: '@s.whatsapp.net',
type: 'set',
xmlns: 'status',
},
content: [{
tag: 'status',
attrs: {},
content: Buffer.from(status, 'utf-8')
}]
})
return status
}
Fernazer.downloadAndSaveMediaMessage = async (message, filename, attachExtension = true) => {
let quoted = message.msg ? message.msg : message
let mime = (message.msg || message).mimetype || ''
let messageType = message.mtype ? message.mtype.replace(/Message/gi, '') : mime.split('/')[0]
const stream = await downloadContentFromMessage(quoted, messageType)
let buffer = Buffer.from([])
for await(const chunk of stream) {
buffer = Buffer.concat([buffer, chunk])
}
let type = await FileType.fromBuffer(buffer)
trueFileName = attachExtension ? (filename + '.' + type.ext) : filename
await fs.writeFileSync(trueFileName, buffer)
return trueFileName
}
Fernazer.downloadMediaMessage = async (message) => {
let mime = (message.msg || message).mimetype || ''
let messageType = message.mtype ? message.mtype.replace(/Message/gi, '') : mime.split('/')[0]
const stream = await downloadContentFromMessage(message, messageType)
let buffer = Buffer.from([])
for await(const chunk of stream) {
buffer = Buffer.concat([buffer, chunk])
}
return buffer
}
Fernazer.sendText = (jid, text, quoted = '', options) => Fernazer.sendMessage(jid, { text: text, ...options }, { quoted })
}
start()
} catch (e) {
console.log(e)
}
}
module.exports = { jadibot, conns }