forked from Adiixyz/Adii-MD02
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
30 lines (26 loc) · 1.18 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
require('./config.js')
'use strict'
const P = require('pino')
const handler = require('./handler.js')
const simple = require('./lib/simple.js')
const { useSingleFileAuthState } = require('@adiwajshing/baileys-md')
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] } : {}) })) : '')
let authFile = './adii.json'
const { state, saveState } = useSingleFileAuthState(authFile)
async function start() {
global.conn = simple.makeWASocket({
logger: P({ level: 'fatal' }),
browser: ['AdiiMD'],
printQRInTerminal: true,
auth: state
})
conn.ev.on('connection.update', (update) => {
console.log('Connection update:', update)
if (update.connection === 'open') console.log(conn.user)
else if (update.connection === 'close') start()
})
conn.ev.on('creds.update', () => saveState)
conn.ev.on('messages.upsert', handler.chatUpdate)
conn.ev.on('group-participants.update', handler.participantsUpdate)
}
start()