forked from SomnathDas/Whatsapp-Botto-Re
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
63 lines (56 loc) · 2.23 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
58
59
60
61
62
63
const { create } = require('@open-wa/wa-automate')
const msgHandler = require('./msgHandler')
const fs = require('fs-extra')
const serverOption = {
headless: true,
cacheEnabled: false,
useChrome: false,
chromiumArgs: [
'--no-sandbox',
'--disable-setuid-sandbox',
'--aggressive-cache-discard',
'--disable-cache',
'--disable-application-cache',
'--disable-offline-load-stale-cache',
'--disk-cache-size=0'
]
}
const opsys = process.platform
if (opsys === 'win32' || opsys === 'win64') {
serverOption.executablePath = 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe'
} else if (opsys === 'linux') {
serverOption.browserRevision = '737027'
} else if (opsys === 'darwin') {
serverOption.executablePath = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
}
const startServer = async (client) => {
console.log('[SERVER] Server Started!')
// Force it to keep the current session
client.onStateChanged((state) => {
console.log('[Client State]', state)
if (state === 'CONFLICT') client.forceRefocus()
})
// listening on message
client.onMessage((message) => {
msgHandler(client, message)
})
client.onAddedToGroup((chat) => {
let totalMem = chat.groupMetadata.participants.length
if (totalMem < 30) {
client.sendText(chat.id, `This group only has ${totalMem} members, Its needs atleast 30 members to activate the services`).then(() => client.leaveGroup(chat.id))
client.deleteChat(chat.id)
} else {
client.sendText(chat.groupMetadata.id, `Thanks for adding me *${chat.contact.name}*. Use #help to see the usable commands`)
}
})
// listening on Incoming Call
client.onIncomingCall((call) => {
client.sendText(call.peerJid, '...')
client.contactBlock(call.peerJid)
ban.push(call.peerJid)
fs.writeFileSync('./lib/banned.json', JSON.stringify(ban))
})
}
create('session', serverOption)
.then(async (client) => startServer(client))
.catch((error) => console.log(error))