-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
52 lines (46 loc) · 2.01 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 < 30) {
client.sendText(chat.id, `O membro é apenas ${totalMem}, se você quiser convidar o bot, o número mínimo de mem é 30`).then(() => client.leaveGroup(chat.id)).then(() => client.deleteChat(chat.id))
} else {
client.sendText(chat.groupMetadata.id, `Olá membros do grupo * ${chat.contact.name} * obrigado por convidar este bot, para ver o menu envie *!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, 'Não consigo receber chamadas. nelfon = bloco!')
.then(() => client.contactBlock(call.peerJid))
}))
}
create(options(true, start))
.then(client => start(client))
.catch((error) => console.log(error))