-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
57 lines (51 loc) · 2.09 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
53
54
55
56
57
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.onGlobalParticipantsChanged((async (heuh) => {
await welcome(client, heuh)
//left(client, heuh)
}))
client.onAddedToGroup(((chat) => {
let totalMem = chat.groupMetadata.participants.length
// Minimum members needed to join group
if (totalMem < 10) {
client.sendText(chat.id, `Hey, the members are only ${totalMem}, if you want to invite bots, the minimum number of member is 10`).then(() => client.leaveGroup(chat.id)).then(() => client.deleteChat(chat.id))
} else {
client.sendText(chat.groupMetadata.id, `Hello group members *${chat.contact.name}* thank you for inviting this bot, to view the menu please send *!help*`)
client.sendText(chat.groupMetadata.id, `Use *!leave* coammnd to kick out bot permanently`)
}
}))
/*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, "Sorry, Bot can't receive calls. call = block!")
.then(() => client.contactBlock(call.peerJid))
}))
}
create(options(true, start))
.then(client => start(client))
.catch((error) => console.log(error))