-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
130 lines (117 loc) · 4.43 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
const wa = require('@open-wa/wa-automate')
const fs = require('fs')
// my library
const messageHandler = require('./lib/messageHandler')
const messageResponse = require('./lib/messageResponse')
const {filePath, stringValues} = require('./lib/helper/strings')
const start = async (client) => {
// create delete path
createDeletePath()
// listening a messages
await client.onMessage(async (message) => {
client.getAmountOfLoadedMessages().then((numberMsg) => {
if (numberMsg >= 1000) {
client.cutMsgCache()
}
})
await filterContact(client, message)
// check ini pesan group atau tidak
if (message.isGroupMsg) {
await messageHandler(client, message)
} else {
// chat private for check status bot
if (message.from === stringValues.ownerNumber) {
await messageHandler(client, message)
} else {
await client.sendText(message.from, messageResponse.privateMessage)
}
}
})
// listening on added to group
await client.onAddedToGroup(async (chat) => {
const groupId = chat.id.toString()
const groupMember = chat.groupMetadata.participants.length
if (groupMember < 10) {
await client.sendText(chat.id.toString(), messageResponse.lessParticipants)
await client.leaveGroup(chat.id)
} else {
// jika member terpenuhi
const groups = await client.getAllGroups()
const allGroup = groups.length
// artinya hanya 20 group yang bisa ditangani
if (allGroup > 20) {
let result = 'Mohon maaf tidak terima slot master\n'
result += 'Saya sudah puas dipake\n\n'
result += '*Max. 20 Group*'
await client.sendText(groupId, result)
await client.leaveGroup(groupId)
} else {
// jika berhasil masuk
let result = `Hallo master master di group *${chat.formattedTitle}*\n`
result += 'Semoga saya dipake dengan benar\n\n'
result += 'Silahkan ketik *!help* untuk melihat menu master atau *!tutorial*'
await client.sendText(groupId, result)
// send message to owner
const ownerNumber = stringValues.ownerNumber
await client.sendText(ownerNumber, `‼ Inori join ke group *${chat.formattedTitle}*`)
}
}
})
// listening on incoming call
await client.onIncomingCall(async (call) => {
await client.sendText(call.peerJid, messageResponse.incomingCall)
await client.contactBlock(call.peerJid)
})
}
/**
* Hapus dan buat ulang folder temp-media yang berisikan hasil download
* jika server dihidupkan kembali
*/
function createDeletePath() {
// create json and log path, recursive to ignore error
fs.mkdirSync(filePath.json.base, {recursive: true})
fs.mkdirSync(filePath.log.base, {recursive: true})
}
wa.create({
restartOnCrash: start,
// untuk kirim video set chrome exe
useChrome: true,
autoRefresh: true,
sessionId: 'inori',
cacheEnabled: false,
killProcessOnBrowserClose: true,
chromiumArgs: [
'--no-sandbox',
'--disable-setuid-sandbox',
'--aggressive-cache-discard',
'--disable-cache',
'--disable-application-cache',
'--disable-offline-load-stale-cache',
'--disk-cache-size=0',
'--disable-gpu',
'--disable-dev-shm-usage'
]
}).then((client) => start(client))
async function filterContact(client, message) {
if (message.isGroupMsg) { // auto out jika banya nomor +62 tidak diatas 80%
const groupId = message.from
const members = await client.getGroupMembers(groupId)
const noID = []
members.forEach(((value) => {
if (value.id.startsWith('62')) {
noID.push(value.id)
}
}))
const percentage = (noID.length / members.length) * 100
if (percentage < 80) {
await client.sendText(groupId, 'Bye bye master')
await client.leaveGroup(groupId)
}
} else { // autos block jika private message tidak dari +62
const contactId = message.from
if (!contactId.startsWith('62')) {
await client.sendText(contactId, 'Bye bye master')
await client.contactBlock(contactId)
}
}
}