-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
52 lines (46 loc) · 2.08 KB
/
index.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
const { create, Client } = require('@open-wa/wa-automate')
const welcome = require('./lib/welcome')
const msgHandler = require('./msgHndlr')
const options = require('./options')
const start = async (client = new Client()) => {
console.log('[SERVER] Server Started!')
// Force it to keep the current session
client.onStateChanged((state) => {
console.log('[Client State]', state)
if (state === 'CONFLICT' || state === 'UNLAUNCHED') client.forceRefocus()
})
// listening on message
client.onMessage((async (message) => {
client.getAmountOfLoadedMessages()
.then((msg) => {
if (msg >= 3000) {
client.cutMsgCache()
}
})
msgHandler(client, message)
}))
client.onGlobalParicipantsChanged((async (heuh) => {
await welcome(client, heuh)
//left(client, heuh)
}))
client.onAddedToGroup(((chat) => {
let totalMem = chat.groupMetadata.participants.length
if (totalMem < 10) {
client.sendText(chat.id, `Cih member nya cuma ${totalMem}, Kalo mau invite bot, minimal jumlah mem ada 10`).then(() => client.leaveGroup(chat.id)).then(() => client.deleteChat(chat.id))
} else {
client.sendText(chat.groupMetadata.id, `Halo warga grup *${chat.contact.name}* terimakasih sudah menginvite bot ini, untuk melihat menu silahkan kirim *!help*`)
}
}))
/*client.onAck((x => {
const { from, to, ack } = x
if (x !== 3) client.sendSeen(to)
}))*/
// listening on Incoming Call
client.onIncomingCall(( async (call) => {
await client.sendText(call.peerJid, 'Maaf, saya tidak bisa menerima panggilan. nelfon = block!')
.then(() => client.contactBlock(call.peerJid))
}))
}
create('BarBar', options(true, start))
.then(client => start(client))
.catch((error) => console.log(error))