Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
jajbshjahavahh
GitHub Repository: jajbshjahavahh/Gojo-Satoru
Path: blob/master/index.js
2390 views
1
//═══════════════════════════════════════════════════════//
2
//
3
// 𝙶𝙾𝙹𝙾-𝚂𝙰𝚃𝙾𝚁𝚄 𝓫𝔂 𝓷𝓮𝔁𝓾𝓼𝓝𝔀
4
//𝙰𝙳𝙾𝙿𝚃𝙴𝙳 𝙵𝚁𝙾𝙼 𝚂𝙲𝚁𝙸𝙿𝚃 𝙾𝙵 𝙲𝙷𝙴𝙴𝙼𝚂𝙱𝙾𝚃 𝚅2 𝙱𝚈 𝙳𝙶𝚇𝚎𝚘𝚗
5
//
6
//════════════════════════════//
7
8
require('./settings')
9
const { default: NexusNwIncConnect, useSingleFileAuthState, DisconnectReason, fetchLatestBaileysVersion, generateForwardMessageContent, prepareWAMessageMedia, generateWAMessageFromContent, generateMessageID, downloadContentFromMessage, makeInMemoryStore, jidDecode, proto } = require("@adiwajshing/baileys")
10
const { state, saveState } = useSingleFileAuthState(`./${sessionName}.json`)
11
const pino = require('pino')
12
const { Boom } = require('@hapi/boom')
13
const fs = require('fs')
14
const yargs = require('yargs/yargs')
15
const chalk = require('chalk')
16
const FileType = require('file-type')
17
const path = require('path')
18
const PhoneNumber = require('awesome-phonenumber')
19
const { imageToWebp, videoToWebp, writeExifImg, writeExifVid } = require('./lib/exif')
20
const { smsg, isUrl, generateMessageTag, getBuffer, getSizeMedia, fetchJson, await, sleep } = require('./lib/myfunc')
21
22
var low
23
try {
24
low = require('lowdb')
25
} catch (e) {
26
low = require('./lib/lowdb')
27
}
28
29
const { Low, JSONFile } = low
30
const mongoDB = require('./lib/mongoDB')
31
32
global.api = (name, path = '/', query = {}, apikeyqueryname) => (name in global.APIs ? global.APIs[name] : name) + path + (query || apikeyqueryname ? '?' + new URLSearchParams(Object.entries({ ...query, ...(apikeyqueryname ? { [apikeyqueryname]: global.APIKeys[name in global.APIs ? global.APIs[name] : name] } : {}) })) : '')
33
34
const store = makeInMemoryStore({ logger: pino().child({ level: 'silent', stream: 'store' }) })
35
36
global.opts = new Object(yargs(process.argv.slice(2)).exitProcess(false).parse())
37
global.db = new Low(
38
/https?:\/\//.test(opts['db'] || '') ?
39
new cloudDBAdapter(opts['db']) : /mongodb/.test(opts['db']) ?
40
new mongoDB(opts['db']) :
41
new JSONFile(`database/database.json`)
42
)
43
global.db.data = {
44
users: {},
45
chats: {},
46
database: {},
47
game: {},
48
settings: {},
49
others: {},
50
sticker: {},
51
...(global.db.data || {})
52
}
53
54
// save database every 30seconds
55
if (global.db) setInterval(async () => {
56
if (global.db.data) await global.db.write()
57
}, 30 * 1000)
58
59
async function startGojoMdNx() {
60
const GojoMdNx = NexusNwIncConnect({
61
logger: pino({ level: 'silent' }),
62
printQRInTerminal: true,
63
browser: ['Gojo Satoru\Nexus','Safari','1.0.0'],
64
auth: state
65
})
66
67
store.bind(GojoMdNx.ev)
68
69
// anticall auto block
70
GojoMdNx.ws.on('CB:call', async (json) => {
71
const callerId = json.content[0].attrs['call-creator']
72
if (json.content[0].tag == 'offer') {
73
let pa7rick = await GojoMdNx.sendContact(callerId, global.owner)
74
GojoMdNx.sendMessage(callerId, { text: `Automatic Block System!\nDon't Call Bot!\nPlease Ask Or Contact The Owner To Unblock You!`}, { quoted : pa7rick })
75
await sleep(8000)
76
await GojoMdNx.updateBlockStatus(callerId, "block")
77
}
78
})
79
80
GojoMdNx.ev.on('messages.upsert', async chatUpdate => {
81
//console.log(JSON.stringify(chatUpdate, undefined, 2))
82
try {
83
mek = chatUpdate.messages[0]
84
if (!mek.message) return
85
mek.message = (Object.keys(mek.message)[0] === 'ephemeralMessage') ? mek.message.ephemeralMessage.message : mek.message
86
if (mek.key && mek.key.remoteJid === 'status@broadcast') return
87
if (!GojoMdNx.public && !mek.key.fromMe && chatUpdate.type === 'notify') return
88
if (mek.key.id.startsWith('BAE5') && mek.key.id.length === 16) return
89
m = smsg(GojoMdNx, mek, store)
90
require("./Gojosensei")(GojoMdNx, m, chatUpdate, store)
91
} catch (err) {
92
console.log(err)
93
}
94
})
95
96
// Group Update
97
GojoMdNx.ev.on('groups.update', async pea => {
98
//console.log(pea)
99
// Get Profile Picture Group
100
try {
101
ppgc = await GojoMdNx.profilePictureUrl(pea[0].id, 'image')
102
} catch {
103
ppgc = 'https://shortlink.GojoMdNxarridho.my.id/rg1oT'
104
}
105
let wm_fatih = { url : ppgc }
106
if (pea[0].announce == true) {
107
GojoMdNx.send5ButImg(pea[0].id, `「 Group Settings Changed 」\n\nThe Group Has Been Closed By Admin, Now Only Admin Can Send Messages !`, `Group Settings Change Message`, wm_fatih, [])
108
} else if(pea[0].announce == false) {
109
GojoMdNx.send5ButImg(pea[0].id, `「 Group Settings Changed 」\n\nThe Group Has Been Opened By Admin, Now Participants Can Send Messages !`, `Group Settings Change Message`, wm_fatih, [])
110
} else if (pea[0].restrict == true) {
111
GojoMdNx.send5ButImg(pea[0].id, `「 Group Settings Changed 」\n\nGroup Info Has Been Restricted, Now Only Admin Can Edit Group Info !`, `Group Settings Change Message`, wm_fatih, [])
112
} else if (pea[0].restrict == false) {
113
GojoMdNx.send5ButImg(pea[0].id, `「 Group Settings Changed 」\n\nGroup Info Has Been Opened, Now Participants Can Edit Group Info !`, `Group Settings Change Message`, wm_fatih, [])
114
} else {
115
GojoMdNx.send5ButImg(pea[0].id, `「 Group Settings Changed 」\n\nGroup Subject Has Been Changed To *${pea[0].subject}*`, `Group Settings Change Message`, wm_fatih, [])
116
}
117
})
118
119
GojoMdNx.ev.on('group-participants.update', async (anu) => {
120
console.log(anu)
121
try {
122
let metadata = await GojoMdNx.groupMetadata(anu.id)
123
let participants = anu.participants
124
for (let num of participants) {
125
// Get Profile Picture User
126
try {
127
ppuser = await GojoMdNx.profilePictureUrl(num, 'image')
128
} catch {
129
ppuser = 'https://i0.wp.com/www.gambarunik.id/wp-content/uploads/2019/06/Top-Gambar-Foto-Profil-Kosong-Lucu-Tergokil-.jpg'
130
}
131
132
//Get Profile Picture Group\\
133
try {
134
ppgroup = await GojoMdNx.profilePictureUrl(anu.id, 'image')
135
} catch {
136
ppgroup = 'https://i0.wp.com/www.gambarunik.id/wp-content/uploads/2019/06/Top-Gambar-Foto-Profil-Kosong-Lucu-Tergokil-.jpg'
137
}
138
139
//welcome\\
140
let nama = await GojoMdNx.getName(num)
141
memb = metadata.participants.length
142
143
Kon = await getBuffer(`https://hardianto.xyz/api/welcome3?profile=${encodeURIComponent(ppuser)}&name=${encodeURIComponent(nama)}&bg=https://telegra.ph/file/8bbe8a7de5c351dfcb077.jpg&namegb=${encodeURIComponent(metadata.subject)}&member=${encodeURIComponent(memb)}`)
144
145
Tol = await getBuffer(`https://hardianto.xyz/api/goodbye3?profile=${encodeURIComponent(ppuser)}&name=${encodeURIComponent(nama)}&bg=https://telegra.ph/file/8bbe8a7de5c351dfcb077.jpg&namegb=${encodeURIComponent(metadata.subject)}&member=${encodeURIComponent(memb)}`)
146
if (anu.action == 'add') {
147
GojoMdNx.sendMessage(anu.id, { image: Kon, contextInfo: { mentionedJid: [num] }, caption: `
148
⭐✑ Hi👋 @${num.split("@")[0]},
149
⭐✑ Welcome To ${metadata.subject}
150
151
⭐✑ Description: ${metadata.desc}
152
153
⭐✑ Welcome To Our Comfortable Happy😋, Sometimes Loud😜, Usually Messy🤥, Full Of Love🥰, HOME😌!!`} )
154
} else if (anu.action == 'remove') {
155
GojoMdNx.sendMessage(anu.id, { image: Tol, contextInfo: { mentionedJid: [num] }, caption: `⭐✑ @${num.split("@")[0]} Left ${metadata.subject}
156
157
⭐✑ I'm Not Sure If It Was A Goodbye Charm, But It Was Fun While It Lasted 😌✨` })
158
}
159
}
160
} catch (err) {
161
console.log(err)
162
}
163
})
164
165
//Setting\\
166
GojoMdNx.decodeJid = (jid) => {
167
if (!jid) return jid
168
if (/:\d+@/gi.test(jid)) {
169
let decode = jidDecode(jid) || {}
170
return decode.user && decode.server && decode.user + '@' + decode.server || jid
171
} else return jid
172
}
173
174
GojoMdNx.ev.on('contacts.update', update => {
175
for (let contact of update) {
176
let id = GojoMdNx.decodeJid(contact.id)
177
if (store && store.contacts) store.contacts[id] = { id, name: contact.notify }
178
}
179
})
180
181
GojoMdNx.getName = (jid, withoutContact = false) => {
182
id = GojoMdNx.decodeJid(jid)
183
withoutContact = GojoMdNx.withoutContact || withoutContact
184
let v
185
if (id.endsWith("@g.us")) return new Promise(async (resolve) => {
186
v = store.contacts[id] || {}
187
if (!(v.name || v.subject)) v = GojoMdNx.groupMetadata(id) || {}
188
resolve(v.name || v.subject || PhoneNumber('+' + id.replace('@s.whatsapp.net', '')).getNumber('international'))
189
})
190
else v = id === '[email protected]' ? {
191
id,
192
name: 'WhatsApp'
193
} : id === GojoMdNx.decodeJid(GojoMdNx.user.id) ?
194
GojoMdNx.user :
195
(store.contacts[id] || {})
196
return (withoutContact ? '' : v.name) || v.subject || v.verifiedName || PhoneNumber('+' + jid.replace('@s.whatsapp.net', '')).getNumber('international')
197
}
198
199
GojoMdNx.sendContact = async (jid, kon, quoted = '', opts = {}) => {
200
let list = []
201
for (let i of kon) {
202
list.push({
203
displayName: await GojoMdNx.getName(i + '@s.whatsapp.net'),
204
vcard: `BEGIN:VCARD\nVERSION:3.0\nN:${ownername}\nitem1.TEL;waid=${i}:${i}\nitem1.X-ABLabel:Click To Chat\nitem2.EMAIL;type=INTERNET:${sc}\nitem2.X-ABLabel:Script\nitem3.URL:${myweb}\nitem3.X-ABLabel:Script\nitem4.ADR:;;${region};;;;\nitem4.X-ABLabel:Region\nEND:VCARD`
205
})
206
}
207
GojoMdNx.sendMessage(jid, { contacts: { displayName: `${list.length} Contact`, contacts: list }, ...opts }, { quoted })
208
}
209
210
GojoMdNx.setStatus = (status) => {
211
GojoMdNx.query({
212
tag: 'iq',
213
attrs: {
214
to: '@s.whatsapp.net',
215
type: 'set',
216
xmlns: 'status',
217
},
218
content: [{
219
tag: 'status',
220
attrs: {},
221
content: Buffer.from(status, 'utf-8')
222
}]
223
})
224
return status
225
}
226
227
GojoMdNx.public = true
228
229
GojoMdNx.serializeM = (m) => smsg(GojoMdNx, m, store)
230
231
GojoMdNx.ev.on('connection.update', async (update) => {
232
const { connection, lastDisconnect } = update
233
if (connection === 'close') {
234
let reason = new Boom(lastDisconnect?.error)?.output.statusCode
235
if (reason === DisconnectReason.badSession) { console.log(`Bad Session File, Please Delete Session and Scan Again`); GojoMdNx.logout(); }
236
else if (reason === DisconnectReason.connectionClosed) { console.log("🐦Connection closed, reconnecting...."); startGojoMdNx(); }
237
else if (reason === DisconnectReason.connectionLost) { console.log("🐦Connection Lost from Server, reconnecting..."); startGojoMdNx(); }
238
else if (reason === DisconnectReason.connectionReplaced) { console.log("🐦Connection Replaced, Another New Session Opened, Please Close Current Session First"); GojoMdNx.logout(); }
239
else if (reason === DisconnectReason.loggedOut) { console.log(`🐦Device Logged Out, Please Scan Again And Run.`); GojoMdNx.logout(); }
240
else if (reason === DisconnectReason.restartRequired) { console.log("🐦Restart Required, Restarting..."); startGojoMdNx(); }
241
else if (reason === DisconnectReason.timedOut) { console.log("🐦Connection TimedOut, Reconnecting..."); startGojoMdNx(); }
242
else GojoMdNx.end(`🐦Unknown DisconnectReason: ${reason}|${connection}`)
243
}
244
console.log('Connected...', update)
245
})
246
247
GojoMdNx.ev.on('creds.update', saveState)
248
249
// Add Other
250
/** Send Button 5 Image
251
*
252
* @param {*} jid
253
* @param {*} text
254
* @param {*} footer
255
* @param {*} image
256
* @param [*] button
257
* @param {*} options
258
* @returns
259
*/
260
GojoMdNx.send5ButImg = async (jid , text = '' , footer = '', img, but = [], options = {}) =>{
261
let message = await prepareWAMessageMedia({ image: img }, { upload: GojoMdNx.waUploadToServer })
262
var template = generateWAMessageFromContent(m.chat, proto.Message.fromObject({
263
templateMessage: {
264
hydratedTemplate: {
265
imageMessage: message.imageMessage,
266
"hydratedContentText": text,
267
"hydratedFooterText": footer,
268
"hydratedButtons": but
269
}
270
}
271
}), options)
272
GojoMdNx.relayMessage(jid, template.message, { messageId: template.key.id })
273
}
274
275
/**
276
*
277
* @param {*} jid
278
* @param {*} buttons
279
* @param {*} caption
280
* @param {*} footer
281
* @param {*} quoted
282
* @param {*} options
283
*/
284
GojoMdNx.sendButtonText = (jid, buttons = [], text, footer, quoted = '', options = {}) => {
285
let buttonMessage = {
286
text,
287
footer,
288
buttons,
289
headerType: 2,
290
...options
291
}
292
GojoMdNx.sendMessage(jid, buttonMessage, { quoted, ...options })
293
}
294
295
/**
296
*
297
* @param {*} jid
298
* @param {*} text
299
* @param {*} quoted
300
* @param {*} options
301
* @returns
302
*/
303
GojoMdNx.sendText = (jid, text, quoted = '', options) => GojoMdNx.sendMessage(jid, { text: text, ...options }, { quoted })
304
305
/**
306
*
307
* @param {*} jid
308
* @param {*} path
309
* @param {*} caption
310
* @param {*} quoted
311
* @param {*} options
312
* @returns
313
*/
314
GojoMdNx.sendImage = async (jid, path, caption = '', quoted = '', options) => {
315
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)
316
return await GojoMdNx.sendMessage(jid, { image: buffer, caption: caption, ...options }, { quoted })
317
}
318
319
/**
320
*
321
* @param {*} jid
322
* @param {*} path
323
* @param {*} caption
324
* @param {*} quoted
325
* @param {*} options
326
* @returns
327
*/
328
GojoMdNx.sendVideo = async (jid, path, caption = '', quoted = '', gif = false, options) => {
329
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)
330
return await GojoMdNx.sendMessage(jid, { video: buffer, caption: caption, gifPlayback: gif, ...options }, { quoted })
331
}
332
333
/**
334
*
335
* @param {*} jid
336
* @param {*} path
337
* @param {*} quoted
338
* @param {*} mime
339
* @param {*} options
340
* @returns
341
*/
342
GojoMdNx.sendAudio = async (jid, path, quoted = '', ptt = false, options) => {
343
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)
344
return await GojoMdNx.sendMessage(jid, { audio: buffer, ptt: ptt, ...options }, { quoted })
345
}
346
347
/**
348
*
349
* @param {*} jid
350
* @param {*} text
351
* @param {*} quoted
352
* @param {*} options
353
* @returns
354
*/
355
GojoMdNx.sendTextWithMentions = async (jid, text, quoted, options = {}) => GojoMdNx.sendMessage(jid, { text: text, contextInfo: { mentionedJid: [...text.matchAll(/@(\d{0,16})/g)].map(v => v[1] + '@s.whatsapp.net') }, ...options }, { quoted })
356
357
/**
358
*
359
* @param {*} jid
360
* @param {*} path
361
* @param {*} quoted
362
* @param {*} options
363
* @returns
364
*/
365
GojoMdNx.sendImageAsSticker = async (jid, path, quoted, options = {}) => {
366
let buff = 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)
367
let buffer
368
if (options && (options.packname || options.author)) {
369
buffer = await writeExifImg(buff, options)
370
} else {
371
buffer = await imageToWebp(buff)
372
}
373
374
await GojoMdNx.sendMessage(jid, { sticker: { url: buffer }, ...options }, { quoted })
375
return buffer
376
}
377
378
/**
379
*
380
* @param {*} jid
381
* @param {*} path
382
* @param {*} quoted
383
* @param {*} options
384
* @returns
385
*/
386
GojoMdNx.sendVideoAsSticker = async (jid, path, quoted, options = {}) => {
387
let buff = 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)
388
let buffer
389
if (options && (options.packname || options.author)) {
390
buffer = await writeExifVid(buff, options)
391
} else {
392
buffer = await videoToWebp(buff)
393
}
394
395
await GojoMdNx.sendMessage(jid, { sticker: { url: buffer }, ...options }, { quoted })
396
return buffer
397
}
398
399
/**
400
*
401
* @param {*} message
402
* @param {*} filename
403
* @param {*} attachExtension
404
* @returns
405
*/
406
GojoMdNx.downloadAndSaveMediaMessage = async (message, filename, attachExtension = true) => {
407
let quoted = message.msg ? message.msg : message
408
let mime = (message.msg || message).mimetype || ''
409
let messageType = message.mtype ? message.mtype.replace(/Message/gi, '') : mime.split('/')[0]
410
const stream = await downloadContentFromMessage(quoted, messageType)
411
let buffer = Buffer.from([])
412
for await(const chunk of stream) {
413
buffer = Buffer.concat([buffer, chunk])
414
}
415
let type = await FileType.fromBuffer(buffer)
416
trueFileName = attachExtension ? (filename + '.' + type.ext) : filename
417
// save to file
418
await fs.writeFileSync(trueFileName, buffer)
419
return trueFileName
420
}
421
422
GojoMdNx.downloadMediaMessage = async (message) => {
423
let mime = (message.msg || message).mimetype || ''
424
let messageType = message.mtype ? message.mtype.replace(/Message/gi, '') : mime.split('/')[0]
425
const stream = await downloadContentFromMessage(message, messageType)
426
let buffer = Buffer.from([])
427
for await(const chunk of stream) {
428
buffer = Buffer.concat([buffer, chunk])
429
}
430
431
return buffer
432
}
433
434
/**
435
*
436
* @param {*} jid
437
* @param {*} path
438
* @param {*} filename
439
* @param {*} caption
440
* @param {*} quoted
441
* @param {*} options
442
* @returns
443
*/
444
GojoMdNx.sendMedia = async (jid, path, fileName = '', caption = '', quoted = '', options = {}) => {
445
let types = await GojoMdNx.getFile(path, true)
446
let { mime, ext, res, data, filename } = types
447
if (res && res.status !== 200 || file.length <= 65536) {
448
try { throw { json: JSON.parse(file.toString()) } }
449
catch (e) { if (e.json) throw e.json }
450
}
451
let type = '', mimetype = mime, pathFile = filename
452
if (options.asDocument) type = 'document'
453
if (options.asSticker || /webp/.test(mime)) {
454
let { writeExif } = require('./lib/exif')
455
let media = { mimetype: mime, data }
456
pathFile = await writeExif(media, { packname: options.packname ? options.packname : global.packname, author: options.author ? options.author : global.author, categories: options.categories ? options.categories : [] })
457
await fs.promises.unlink(filename)
458
type = 'sticker'
459
mimetype = 'image/webp'
460
}
461
else if (/image/.test(mime)) type = 'image'
462
else if (/video/.test(mime)) type = 'video'
463
else if (/audio/.test(mime)) type = 'audio'
464
else type = 'document'
465
await GojoMdNx.sendMessage(jid, { [type]: { url: pathFile }, caption, mimetype, fileName, ...options }, { quoted, ...options })
466
return fs.promises.unlink(pathFile)
467
}
468
469
/**
470
*
471
* @param {*} jid
472
* @param {*} message
473
* @param {*} forceForward
474
* @param {*} options
475
* @returns
476
*/
477
GojoMdNx.copyNForward = async (jid, message, forceForward = false, options = {}) => {
478
let vtype
479
if (options.readViewOnce) {
480
message.message = message.message && message.message.ephemeralMessage && message.message.ephemeralMessage.message ? message.message.ephemeralMessage.message : (message.message || undefined)
481
vtype = Object.keys(message.message.viewOnceMessage.message)[0]
482
delete(message.message && message.message.ignore ? message.message.ignore : (message.message || undefined))
483
delete message.message.viewOnceMessage.message[vtype].viewOnce
484
message.message = {
485
...message.message.viewOnceMessage.message
486
}
487
}
488
489
let mtype = Object.keys(message.message)[0]
490
let content = await generateForwardMessageContent(message, forceForward)
491
let ctype = Object.keys(content)[0]
492
let context = {}
493
if (mtype != "conversation") context = message.message[mtype].contextInfo
494
content[ctype].contextInfo = {
495
...context,
496
...content[ctype].contextInfo
497
}
498
const waMessage = await generateWAMessageFromContent(jid, content, options ? {
499
...content[ctype],
500
...options,
501
...(options.contextInfo ? {
502
contextInfo: {
503
...content[ctype].contextInfo,
504
...options.contextInfo
505
}
506
} : {})
507
} : {})
508
await GojoMdNx.relayMessage(jid, waMessage.message, { messageId: waMessage.key.id })
509
return waMessage
510
}
511
512
GojoMdNx.cMod = (jid, copy, text = '', sender = GojoMdNx.user.id, options = {}) => {
513
//let copy = message.toJSON()
514
let mtype = Object.keys(copy.message)[0]
515
let isEphemeral = mtype === 'ephemeralMessage'
516
if (isEphemeral) {
517
mtype = Object.keys(copy.message.ephemeralMessage.message)[0]
518
}
519
let msg = isEphemeral ? copy.message.ephemeralMessage.message : copy.message
520
let content = msg[mtype]
521
if (typeof content === 'string') msg[mtype] = text || content
522
else if (content.caption) content.caption = text || content.caption
523
else if (content.text) content.text = text || content.text
524
if (typeof content !== 'string') msg[mtype] = {
525
...content,
526
...options
527
}
528
if (copy.key.participant) sender = copy.key.participant = sender || copy.key.participant
529
else if (copy.key.participant) sender = copy.key.participant = sender || copy.key.participant
530
if (copy.key.remoteJid.includes('@s.whatsapp.net')) sender = sender || copy.key.remoteJid
531
else if (copy.key.remoteJid.includes('@broadcast')) sender = sender || copy.key.remoteJid
532
copy.key.remoteJid = jid
533
copy.key.fromMe = sender === GojoMdNx.user.id
534
535
return proto.WebMessageInfo.fromObject(copy)
536
}
537
538
539
/**
540
*
541
* @param {*} path
542
* @returns
543
*/
544
GojoMdNx.getFile = async (PATH, save) => {
545
let res
546
let data = Buffer.isBuffer(PATH) ? PATH : /^data:.*?\/.*?;base64,/i.test(PATH) ? Buffer.from(PATH.split`,`[1], 'base64') : /^https?:\/\//.test(PATH) ? await (res = await getBuffer(PATH)) : fs.existsSync(PATH) ? (filename = PATH, fs.readFileSync(PATH)) : typeof PATH === 'string' ? PATH : Buffer.alloc(0)
547
//if (!Buffer.isBuffer(data)) throw new TypeError('Result is not a buffer')
548
let type = await FileType.fromBuffer(data) || {
549
mime: 'application/octet-stream',
550
ext: '.bin'
551
}
552
filename = path.join(__filename, '../src/' + new Date * 1 + '.' + type.ext)
553
if (data && save) fs.promises.writeFile(filename, data)
554
return {
555
res,
556
filename,
557
size: await getSizeMedia(data),
558
...type,
559
data
560
}
561
562
}
563
564
return GojoMdNx
565
}
566
567
startGojoMdNx()
568
569
570
let file = require.resolve(__filename)
571
fs.watchFile(file, () => {
572
fs.unwatchFile(file)
573
console.log(chalk.redBright(`Update ${__filename}`))
574
delete require.cache[file]
575
require(file)
576
})
577
578