-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
133 lines (118 loc) · 4.97 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
131
132
133
const { create, Client } = require('@open-wa/wa-automate')
const welcome = require('./lib/welcome')
const left = require('./lib/left')
const intro = require('./lib/intro')
const msgHandler = require('./msgHndlr')
const options = require('./options')
const fs = require('fs')
// AUTO UPDATE BY NURUTOMO
// THX FOR NURUTOMO
// Cache handler and check for file change
require('./msgHndlr.js')
nocache('./msgHndlr.js', module => console.log(`'${module}' Updated!`))
const adminNumber = JSON.parse(fs.readFileSync('./lib/admin.json'))
const setting = JSON.parse(fs.readFileSync('./lib/setting.json'))
const isWhite = (chatId) => adminNumber.includes(chatId) ? true : false
let {
limitCount,
memberLimit,
groupLimit,
banChats,
prefix,
restartState: isRestart,
mtc: mtcState
} = setting
function restartAwal(client){
setting.restartState = false
isRestart = false
client.sendText(setting.restartId, 'Restart Succesfull!')
setting.restartId = 'undefined'
//fs.writeFileSync('./lib/setting.json', JSON.stringify(setting, null,2));
}
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 >= 1000) {
client.cutMsgCache()
}
})
msgHandler(client, message)
}))
client.onGlobalParticipantsChanged((async (heuh) => {
await welcome(client, heuh)
intro(client, heuh)
left(client, heuh)
}))
client.onAddedToGroup(((chat) => {
let totalMem = chat.groupMetadata.participants.length
if (totalMem < 257) {
client.sendText(chat.id, `Halo warga ${name} mohon maaf, jika mau menginvite bot, silahkan membeli akses premium bot melalui wa.me//682301826966`).then(() => client.leaveGroup(chat.id)).then(() => client.deleteChat(chat.id))
} else {
client.sendText(chat.groupMetadata.id, `Hello group members *${name}*, thank you for inviting this bot, to see the bot menu send *#menu*`)
}
}))
/*client.onAck((x => {
const { from, to, ack } = x
if (x !== 3) client.sendSeen(to)
}))*/
// ketika bot diinvite ke dalam group
client.onAddedToGroup(async (chat) => {
const groups = await client.getAllGroups()
// kondisi ketika batas group bot telah tercapai,ubah di file settings/setting.json
if (groups.length > groupLimit) {
await client.sendText(chat.id, `Sorry, bot tidak bisa join di grub untuk menginvite bot silahkan hubungi owner bot https://wa.me/682301826966 max group: ${groupLimit}`).then(() => {
client.leaveGroup(chat.id)
client.deleteChat(chat.id)
})
} else {
// kondisi ketika batas member group belum tercapai, ubah di file settings/setting.json
if (chat.groupMetadata.participants.length < memberLimit) {
await client.sendText(chat.id, `Sorry, BOT comes out if the group members do not exceed ${memberLimit} people`).then(() => {
client.leaveGroup(chat.id)
client.deleteChat(chat.id)
})
} else {
await client.simulateTyping(chat.id, true).then(async () => {
await client.sendText(chat.id, `Hai minna~(*^-^*), Saya BOT TKTSubs ( ノ ゚ー゚)ノ.\nSemoga saya bisa berguna bagi groub ini yah (ノ◕ヮ◕)ノ*:・゚✧\nCara menggunakan bot ini dengan cara mengetik #menu`)
})
}
}
})
// listening on Incoming Call
client.onIncomingCall(( async (call) => {
await client.sendText(call.peerJid, 'Maaf, saya tidak bisa menerima panggilan. nelfon = block!.\nbila ingin di unblock kamu harus berdonasi dan hubungi whatsapp owner: wa.me/682301826966')
.then(() => client.contactBlock(call.peerJid))
}))
}
function nocache(module, cb = () => { }) {
console.log('Module', `'${module}'`, 'is now being watched for changes')
fs.watchFile(require.resolve(module), async () => {
await uncache(require.resolve(module))
cb(module)
})
}
/**
* Uncache a module
* @param {string} module Module name or path
*/
function uncache(module = '.') {
return new Promise((resolve, reject) => {
try {
delete require.cache[require.resolve(module)]
resolve()
} catch (e) {
reject(e)
}
})
}
create(options(true, start))
.then(client => start(client))
.catch((error) => console.log(error))