-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
603 lines (575 loc) · 22.3 KB
/
main.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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
let { WAConnection: _WAConnection, WA_MESSAGE_STUB_TYPES } = require('@adiwajshing/baileys')
let express = require('express')
let { generate } = require('qrcode-terminal')
let qrcode = require('qrcode')
let simple = require('./lib/simple')
let logs = require('./lib/logs')
let yargs = require('yargs/yargs')
let syntaxerror = require('syntax-error')
let fetch = require('node-fetch')
let chalk = require('chalk')
let fs = require('fs')
let path = require('path')
let util = require('util')
let { spawn, spawnSync } = require('child_process')
let Database = require('./lib/database')
let Readline = require('readline')
let rl = Readline.createInterface(process.stdin, process.stdout)
let WAConnection = simple.WAConnection(_WAConnection)
global.owner = ['62895337278647'] // Put your number here
global.mods = [] // Moderator number
global.prems = ['6285806157712'] // Premium user has unlimited limit
global.VIP = ['6285806157712'] // VIP user is premium user forever
global.APIs = { // API Prefix
// name: 'https://website'
nrtm: 'https://nurutomo.herokuapp.com',
xteam: 'https://api.xteam.xyz',
kuhong: 'https://kuhong-api.herokuapp.com',
zahirr: 'https://zahirr-web.herokuapp.com',
zeks: 'https://api.zeks.xyz',
pencarikode: 'https://pencarikode.xyz',
leyscoders: 'https://leyscoders-api.herokuapp.com'
}
global.APIKeys = { // APIKey Here
// 'https://website': 'apikey'
'https://api.xteam.xyz': '7cac32071f2eb2ff',
'https://kuhong-api.herokuapp.com': '8RiU6O-yrLpgVep',
'https://zahirr-web.herokuapp.com': 'zahirgans',
'https://api.zeks.xyz': 'MIMINGANZ',
'https://pencarikode.xyz': 'pais',
'https://leyscoders-api.herokuapp.com': 'dappakntlll'
}
// Sticker WM
global.packname = 'Sticker Maker'
global.author = 'Kuhong Bot'
global.multiplier = 100 // The higher, The harder levelup
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]} : {})})) : '')
global.timestamp = {
start: new Date
}
// global.LOGGER = logs()
let PORT = process.env.PORT || 3000
global.opts = new Object(yargs(process.argv.slice(2)).exitProcess(false).parse())
global.prefix = new RegExp('^[' + (opts['prefix'] || 'xzXZ\\/!#$%*,()[]@1234567890¡¿\\-+£¢€¥§^°=¶∆×÷π√✓©®:;?&._') + ']')
global.DATABASE = new Database(`${opts._[0] ? opts._[0] + '_' : ''}database.json`, null, 2)
if (!global.DATABASE.data.users) global.DATABASE.data.users = {}
if (!global.DATABASE.data.groups) global.DATABASE.data.groups = {}
if (!global.DATABASE.data.chats) global.DATABASE.data.chats = {}
if (!global.DATABASE.data.stats) global.DATABASE.data.stats = {}
if (!global.DATABASE.data.msgs) global.DATABASE.data.msgs = {}
if (opts['server']) {
global.app = express()
app.use(express.static('views'))
app.all('*', async (req, res, next) => {
await global.conn.connect().catch(console.log)
res.end(await qrcode.toBuffer(global.qr))
})
app.listen(PORT, () => console.log('App listened on port', PORT))
}
global.conn = new WAConnection()
let authFile = `${opts._[0] || 'session'}.data.json`
if (fs.existsSync(authFile)) conn.loadAuthInfo(authFile)
if (opts['big-qr'] || opts['server']) conn.on('qr', qr => generate(qr, { small: false }))
if (opts['server']) conn.on('qr', qr => { global.qr = qr })
conn.on('credentials-updated', () => fs.writeFileSync(authFile, JSON.stringify(conn.base64EncodedAuthInfo())))
let lastJSON = JSON.stringify(global.DATABASE.data)
if (!opts['test']) setInterval(() => {
conn.logger.info('Saving database . . .')
if (JSON.stringify(global.DATABASE.data) == lastJSON) conn.logger.info('Database is up to date')
else {
global.DATABASE.save()
conn.logger.info('Done saving database!')
lastJSON = JSON.stringify(global.DATABASE.data)
}
}, 60 * 1000) // Save every minute
let isNumber = x => typeof x === 'number' && !isNaN(x)
conn.handler = async function (m) {
try {
simple.smsg(this, m)
m.exp = 0
m.limit = false
try {
let user
if (user = global.DATABASE._data.users[m.sender]) {
if (!isNumber(user.exp)) user.exp = 0
if (!isNumber(user.limit)) user.limit = 10
if (!isNumber(user.lastclaim)) user.lastclaim = 0
if (!'registered' in user) user.registered = false
if (!user.registered) {
if (!'name' in user) user.name = this.getName(m.sender)
if (!isNumber(user.age)) user.age = -1
if (!isNumber(user.regTime)) user.regTime = -1
}
if (!isNumber(user.afk)) user.afk = -1
if (!'afkReason' in user) user.afkReason = ''
if (!'banned' in user) user.banned = false
if (!isNumber(user.level)) user.level = 1
if (!user.role) user.role = 'Bronze'
if (!'autolevelup' in user) user.autolevelup = true
} else global.DATABASE._data.users[m.sender] = {
exp: 0,
limit: 10,
lastclaim: 0,
registered: false,
name: this.getName(m.sender),
age: -1,
regTime: -1,
afk: -1,
afkReason: '',
banned: false,
level: 1,
role: 'Bronze',
autolevelup: true
}
let chat
if (chat = global.DATABASE._data.chats[m.chat]) {
if (!'isBanned' in chat) chat.isBanned = false
if (!'welcome' in chat) chat.welcome = true
if (!'sWelcome' in chat) chat.sWelcome = ''
if (!'sBye' in chat) chat.sBye = ''
if (!'sPromote' in chat) chat.sPromote = ''
if (!'sDemote' in chat) chat.sDemote = ''
if (!'antidelete' in chat) chat.antidelete = false
if (!'antispam' in chat) chat.antispam = false
if (!'antilink' in chat) chat.antilink = false
if (!'antivirtex' in chat) chat.antivirtex = false
if (!'antitoxic' in chat) chat.antitoxic = false
if (!('simi' in chat)) chat.simi = false
if (!('viewonce' in chat)) chat.viewonce = false
} else global.DATABASE._data.chats[m.chat] = {
isBanned: false,
welcome: true,
sWelcome: '',
sBye: '',
sPromote: '',
sDemote: '',
antidelete: false,
antispam: false,
antilink: false,
antivirtex: false,
antitoxic: false,
simi: false,
viewonce: false
}
} catch (e) {
console.log(e, global.DATABASE.data)
}
if (opts['nyimak']) return
if (!m.fromMe && opts['self']) return
if (!m.text) return
if (typeof m.text !== 'string') m.text = ''
if (m.isBaileys) return
m.exp += Math.ceil(Math.random() * 10)
let usedPrefix
let _user = global.DATABASE._data.users[m.sender]
let isROwner = [global.conn.user.jid, ...global.owner].map(v => v.replace(/[^0-9]/g, '') + '@s.whatsapp.net').includes(m.sender)
let isOwner = isROwner || m.fromMe
let isMods = isOwner || global.mods.map(v => v.replace(/[^0-9]/g, '') + '@s.whatsapp.net').includes(m.sender)
let isPrems = isROwner || global.prems.map(v => v.replace(/[^0-9]/g, '') + '@s.whatsapp.net').includes(m.sender)
let isVIP = isROwner || global.VIP.map(v => v.replace(/[^0-9]/g, '') + '@s.whatsapp.net').includes(m.sender)
let groupMetadata = m.isGroup ? await this.groupMetadata(m.chat) : {}
let participants = m.isGroup ? groupMetadata.participants : []
let user = m.isGroup ? participants.find(u => u.jid == m.sender) : {} // User Data
let bot = m.isGroup ? participants.find(u => u.jid == this.user.jid) : {} // Your Data
let isAdmin = user.isAdmin || user.isSuperAdmin || false // Is User Admin?
let isBotAdmin = bot.isAdmin || bot.isSuperAdmin || false // Are you Admin?
let isBlocked = this.blocklist.map(v => v.replace(/[^0-9]/g, '') + '@s.whatsapp.net').filter(v => v != this.user.jid).includes(m.sender) // Is User Blocked?
for (let name in global.plugins) {
let plugin = global.plugins[name]
if (!plugin) continue
if (!opts['restrict']) if (plugin.tags && plugin.tags.includes('admin')) continue
let str2Regex = str => str.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&')
let _prefix = plugin.customPrefix ? plugin.customPrefix : conn.prefix ? conn.prefix : global.prefix
let match = (_prefix instanceof RegExp ? // RegExp Mode?
[[_prefix.exec(m.text), _prefix]] :
Array.isArray(_prefix) ? // Array?
_prefix.map(p => {
let re = p instanceof RegExp ? // RegExp in Array?
p :
new RegExp(str2Regex(p))
return [re.exec(m.text), re]
}) :
typeof _prefix === 'string' ? // String?
[[new RegExp(str2Regex(_prefix)).exec(m.text), new RegExp(str2Regex(_prefix))]] :
[[[], new RegExp]]
).find(p => p[1])
if (typeof plugin.before == 'function') if (await plugin.before.call(this, m, {
match,
conn: this,
participants,
groupMetadata,
user,
bot,
isROwner,
isOwner,
isMods,
isPrems,
isVIP,
isAdmin,
isBotAdmin,
isBlocked
})) continue
if ((usedPrefix = (_prefix.exec(m.text) || '')[0])) {
let noPrefix = m.text.replace(usedPrefix, '')
let [command, ...args] = noPrefix.trim().split(' ').filter(v=>v)
args = args || []
let _args = noPrefix.trim().split(' ').slice(1)
let text = _args.join(' ')
command = (command || '').toLowerCase()
let fail = plugin.fail || global.dfail // When failed
let isAccept = plugin.command instanceof RegExp ? // RegExp Mode?
plugin.command.test(command) :
Array.isArray(plugin.command) ? // Array?
plugin.command.some(cmd => cmd instanceof RegExp ? // RegExp in Array?
cmd.test(command) :
cmd === command
) :
typeof plugin.command === 'string' ? // String?
plugin.command === command :
false
if (!isAccept) continue
m.plugin = name
if (m.chat in global.DATABASE._data.chats) {
let chat = global.DATABASE._data.chats[m.chat]
let user = global.DATABASE._data.users[m.sender]
if (name !== 'unbanchat.js' && chat && chat.isBanned) return // Ban Chats
if (name !== 'unbanuser.js' && user && user.banned) return // Ban Users
}
if (plugin.rowner && !isROwner) { // Real Owner Number
fail('rowner', m, this)
continue
}
if (plugin.owner && !isOwner) { // Owner Number
fail('owner', m, this)
continue
}
if (plugin.mods && !isMods) { // Moderator User
fail('mods', m, this)
continue
}
if (plugin.premium && !isPrems) { // Premium User
fail('premium', m, this)
continue
}
if (plugin.vip && !isVIP) { // VIP User
fail('vip', m, this)
continue
}
if (plugin.group && !m.isGroup) { // Group Only
fail('group', m, this)
continue
} else if (plugin.botAdmin && !isBotAdmin) { // You Admin
fail('botAdmin', m, this)
continue
} else if (plugin.admin && !isAdmin) { // User Admin
fail('admin', m, this)
continue
}
if (plugin.private && m.isGroup) { // Private Chat Only
fail('private', m, this)
continue
}
if (plugin.register == undefined && _user.registered == false && !isROwner) { // Need Register
fail('unreg', m, this)
continue
}
if (plugin.off) { // Features Non Active
fail('off', m, this)
continue
}
if (plugin.maintenance) { // Features Maintenance
fail('maintenance', m, this)
continue
}
m.isCommand = true
let xp = 'exp' in plugin ? parseInt(plugin.exp) : 10 // XP Earning per command
if (xp > 999) m.reply('*「 CHEAT DETECTED 」*\n\nPenggunaan _cheat_ terdeteksi saat melakukan perintah!') // Hehehe
else m.exp += xp
if (!isPrems && !isVIP && global.DATABASE._data.users[m.sender].limit < m.limit * 1 && plugin.limit) {
this.reply(m.chat, `*「 LIMIT HABIS 」*\n\nLimit anda habis!\nSilahkan beli melalui *${usedPrefix}buy*`, m)
continue // Limit habis
}
try {
await plugin.call(this, m, {
match,
usedPrefix,
noPrefix,
_args,
args,
command,
text,
conn: this,
participants,
groupMetadata,
isROwner,
isOwner,
isMods,
isPrems,
isVIP,
isAdmin,
isBotAdmin,
isBlocked
})
if (!isPrems && !isVIP) m.limit = m.limit || plugin.limit || false
} catch (e) {
// Error occured
m.error = e
console.error(e)
if (e) {
let text = util.format(e.message ? e.message : e)
for (let key of Object.values(global.APIKeys))
text = text.replace(new RegExp(key, 'g'), 'HIDDEN')
m.reply(text)
}
} finally {
// m.reply(util.format(_user))
if (m.limit) m.reply(+ m.limit + ' Limit terpakai')
}
break
}
}
} finally {
// console.log(global.DATABASE._data.users[m.sender])
let user, stats = global.DATABASE._data.stats
if (m) {
if (m.sender && (user = global.DATABASE._data.users[m.sender])) {
user.exp += m.exp
user.limit -= m.limit * 1
}
let stat
if (m.plugin) {
let now = + new Date
if (m.plugin in stats) {
stat = stats[m.plugin]
if (!isNumber(stat.total)) stat.total = 1
if (!isNumber(stat.success)) stat.success = m.error ? 0 : 1
if (!isNumber(stat.last)) stat.last = now
if (!isNumber(stat.lastSuccess)) stat.lastSuccess = m.error ? 0 : now
} else stat = stats[m.plugin] = {
total: 1,
success: m.error ? 0 : 1,
last: now,
lastSuccess: m.error ? 0 : now
}
stat.total += 1
stat.last = now
if (!m.error) {
stat.success += 1
stat.lastSuccess = now
}
}
}
try {
require('./lib/print')(m, this)
} catch (e) {
console.log(m, m.quoted, e)
}
if (opts['autoread']) await this.chatRead(m.chat).catch(() => {})
}
}
conn.welcome = '*「 WELCOME 」*\n\nHalo @user!\nSelamat datang di grup\n*@subject*\n\n@desc'
conn.bye = '*「 GOOD BYE 」*\n\nAl-Fatihah kepada @user\nyang telah keluar dari grup!'
conn.promote = '*「 PROMOTED 」*\n\n@user sekarang adalah _Admin_!'
conn.demote = '*「 DEMOTED 」*\n\n@user sekarang bukan _Admin_ lagi!'
conn.participants = async function ({ jid, participants, action }) {
let chat = global.DATABASE._data.chats[jid]
let text = ''
switch (action) {
case 'add':
case 'remove':
if (chat.welcome) {
let groupMetadata = await this.groupMetadata(jid)
for (let user of participants) {
let pp = './src/avatar_contact.png'
try {
pp = await this.getProfilePicture(user)
} catch (e) {
} finally {
text = (action === 'add' ? (chat.sWelcome || this.welcome || conn.welcome || 'Welcome, @user!').replace('@subject', this.getName(jid)).replace('@desc', groupMetadata.desc) :
(chat.sBye || this.bye || conn.bye || 'Bye, @user!')).replace('@user', '@' + user.split('@')[0])
this.sendFile(jid, pp, 'pp.jpg', text, null, false, {
contextInfo: {
mentionedJid: [user]
}
})
}
}
}
break
case 'promote':
text = (chat.sPromote || this.promote || conn.promote || '@user ```is now Admin```')
case 'demote':
if (!text) text = (chat.sDemote || this.demote || conn.demote || '@user ```is no longer Admin```')
m.reply(text.replace('@user', '@' + participants[0].split('@')[0]))
break
}
}
conn.delete = async function (m) {
if (m.key.fromMe) return
let chat = global.DATABASE._data.chats[m.key.remoteJid]
if (chat.antidelete) return
await this.reply(m.key.remoteJid, `*「 ANTI DELETE 」*\n\nTerdeteksi @${m.participant.split`@`[0]} telah menghapus pesan!`, m.message, {
contextInfo: {
mentionedJid: [m.participant]
}
})
this.copyNForward(m.key.remoteJid, m.message).catch(e => console.log(e, m))
}
conn.on('chat-update', conn.handler)
conn.on('message-delete', conn.delete)
conn.on('group-participants-update', conn.participants)
conn.on('error', conn.logger.error)
conn.on('close', () => {
setTimeout(async () => {
try {
if (conn.state === 'close') {
await conn.loadAuthInfo(authFile)
await conn.connect()
global.timestamp.connect = new Date
}
} catch (e) {
conn.logger.error(e)
}
}, 5000)
})
global.dfail = (type, m, conn) => {
let msg = {
rowner: `*「 KHUSUS KUHONG 」*\n\nPerintah ini hanya dapat digunakan oleh _*Owner Kuhong*_!`,
owner: `*「 KHUSUS OWNER 」*\n\nPerintah ini hanya dapat digunakan oleh _*Owner Bot*_!`,
mods: `*「 KHUSUS MODERATOR 」*\n\nPerintah ini hanya dapat digunakan oleh _*Moderator*_!`,
premium: `*「 KHUSUS PREMIUM 」*\n\nPerintah ini hanya untuk member _*Premium*_!\n\nKetik !premium untuk beli premium`,
vip: `*「 KHUSUS VIP 」*\n\nPerintah ini hanya untuk member _*VIP*_!\n\nKetik !premium untuk beli premium VIP`,
group: `*「 KHUSUS GROUP 」*\n\nPerintah ini hanya dapat digunakan di *Grup*!`,
private: `*「 KHUSUS PRIBADI 」*\n\nPerintah ini hanya dapat digunakan di *Chat Pribadi*!`,
admin: `*「 KHUSUS ADMIN 」*\n\nPerintah ini hanya untuk *Admin* grup!`,
botAdmin: `*「 BOT HARUS ADMIN 」*\n\nJadikan bot sebagai *Admin* untuk menggunakan perintah ini!`,
unreg: `*「 BELUM DAFTAR 」*\n\nSilahkan Daftar terlebih dahulu untuk menggunakan fitur ini dengan cara ketik :\n\n*!daftar nama|umur|kota*\n\nContoh : *!daftar Kuhong|17|Jakarta*`,
off: `*「 TIDAK DIAKTIFKAN 」*\n\nPerintah ini dinonaktifkan oleh _*Owner Bot*_!`,
maintenance: `*「 MAINTENANCE 」*\n\nFitur ini sedang dalam _*Perbaikan*_!`
}[type]
if (msg) m.reply(msg)
}
if (opts['test']) {
conn.user = {
jid: '[email protected]',
name: 'test',
phone: {}
}
conn.chats
conn.prepareMessageMedia = (buffer, mediaType, options = {}) => {
return {
[mediaType]: {
url: '',
mediaKey: '',
mimetype: options.mimetype,
fileEncSha256: '',
fileSha256: '',
fileLength: buffer.length,
seconds: options.duration,
fileName: options.filename || 'file',
gifPlayback: options.mimetype == 'image/gif' || undefined,
caption: options.caption,
ptt: options.ptt
}
}
}
conn.sendMessage = async (chatId, content, type, opts = {}) => {
let message = await conn.prepareMessageContent(content, type, opts)
let waMessage = conn.prepareMessageFromCntent(chatId, message, opts)
if (type == 'conversation') waMessage.key.id = require('crypto').randomBytes(16).toString('hex').toUpperCase()
conn.emit('message-new', waMessage)
}
rl.on('line', line => conn.sendMessage('[email protected]', line.trim(), 'conversation'))
} else {
rl.on('line', line => {
global.DATABASE.save()
process.send(line.trim())
})
conn.connect().then(() => {
global.timestamp.connect = new Date
})
}
process.on('uncaughtException', console.error)
// let strQuot = /(["'])(?:(?=(\\?))\2.)*?\1/
let pluginFolder = path.join(__dirname, 'plugins')
let pluginFilter = filename => /\.js$/.test(filename)
global.plugins = {}
for (let filename of fs.readdirSync(pluginFolder).filter(pluginFilter)) {
try {
global.plugins[filename] = require(path.join(pluginFolder, filename))
} catch (e) {
conn.logger.error(e)
delete global.plugins[filename]
}
}
console.log(Object.keys(global.plugins))
global.reload = (event, filename) => {
if (pluginFilter(filename)) {
let dir = path.join(pluginFolder, filename)
if (dir in require.cache) {
delete require.cache[dir]
if (fs.existsSync(dir)) conn.logger.info(`re - require plugin '${filename}'`)
else {
conn.logger.warn(`deleted plugin '${filename}'`)
return delete global.plugins[filename]
}
} else conn.logger.info(`requiring new plugin '${filename}'`)
let err = syntaxerror(fs.readFileSync(dir), filename)
if (err) conn.logger.error(`syntax error while loading '${filename}'\n${err}`)
else try {
global.plugins[filename] = require(dir)
} catch (e) {
conn.logger.error(e)
}
}
}
Object.freeze(global.reload)
fs.watch(path.join(__dirname, 'plugins'), global.relod)
process.on('exit', () => global.DATABASE.save())
// Quick Test
async function _quickTest() {
let test = await Promise.all([
spawn('ffmpeg'),
spawn('ffprobe'),
spawn('ffmpeg', ['-hide_banner', '-loglevel', 'error', '-filter_complex', 'color', '-frames:v', '1', '-f', 'webp', '-']),
spawn('convert'),
spawn('magick'),
spawn('gm'),
].map(p => {
return Promise.race([
new Promise(resolve => {
p.on('close', code => {
resolve(code !== 127)
})
}),
new Promise(resolve => {
p.on('error', _ => resolve(false))
})
])
}))
let [ffmpeg, ffprobe, ffmpegWebp, convert, magick, gm] = test
console.log(test)
let s = global.support = {
ffmpeg,
ffprobe,
ffmpegWebp,
convert,
magick,
gm
}
require('./lib/sticker').support = s
Object.freeze(global.support)
if (!s.ffmpeg) conn.logger.warn('Please install ffmpeg for sending videos (pkg install ffmpeg)')
if (s.ffmpeg && !s.ffmpegWebp) conn.logger.warn('Stickers may not animated without libwebp on ffmpeg (--enable-ibwebp while compiling ffmpeg)')
if (!s.convert && !s.magick && !s.gm) conn.logger.warn('Stickers may not work without imagemagick if libwebp on ffmpeg doesnt isntalled (pkg install imagemagick)')
}
_quickTest()
.then(() => conn.logger.info('Quick Test Done'))
.catch(console.error)
let file = require.resolve(__filename)
fs.watchFile(file, () => {
fs.unwatchFile(file)
console.log(chalk.redBright("Update 'main.js'"))
delete require.cache[file]
require(file)
})