-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
65 lines (58 loc) · 1.77 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
const {
WAConnection,
MessageType,
Presence,
Mimetype,
GroupSettingChange
} = require('@adiwajshing/baileys')
const fs = require('fs')
const { banner, start, success } = require('./lib/functions')
const { color } = require('./lib/color')
require('./adii.js')
nocache('./adii.js', module => console.log(`${module} is now updated!`))
const starts = async (adii = new WAConnection()) => {
adii.logger.level = 'warn'
console.log(banner.string)
adii.on('qr', () => {
console.log(color('[','white'), color('!','red'), color(']','white'), color(' Scan bang'))
})
fs.existsSync('./Adii.json') && adii.loadAuthInfo('./Adii.json')
adii.on('connecting', () => {
start('2', '2..')
})
adii.on('open', () => {
success('2', '2..')
})
await adii.connect({timeoutMs: 30*1000})
fs.writeFileSync('./Adii.json', JSON.stringify(adii.base64EncodedAuthInfo(), null, '\t'))
adii.on('chat-update', async (message) => {
require('./adii.js')(adii, message)
})
}
/**
* Uncache if there is file change
* @param {string} module Module name or path
* @param {function} cb <optional>
*/
function nocache(module, cb = () => { }) {
console.log('Module', `'${module}'`, 'Telah dipantau oleh kang bakso wkwk')
fs.watchFile(require.resolve(module), async () => {
await uncache(require.resolve(module))
cb(module)
})
}
/**
* Uncache a module
* @param {string} module Module name or path
*/
function uncache(module = '.') {
return new Promise((resolve, reject) => {
try {
delete require.cache[require.resolve(module)]
resolve()
} catch (e) {
reject(e)
}
})
}
starts()