forked from neoxr/neoxr-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler.js
225 lines (224 loc) · 12.3 KB
/
handler.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
const moment = require('moment-timezone')
moment.tz.setDefault('Asia/Jakarta').locale('id')
module.exports = async (client, m) => {
try {
require('./system/database')(m)
const isOwner = [global.owner, ...global.db.setting.owners].map(v => v + '@s.whatsapp.net').includes(m.sender)
const isPrem = (typeof global.db.users[m.sender] != 'undefined' && global.db.users[m.sender].premium) || isOwner
const groupMetadata = m.isGroup ? await client.groupMetadata(m.chat) : {}
const participants = m.isGroup ? groupMetadata.participants : [] || []
const adminList = m.isGroup ? await client.groupAdmin(m.chat) : [] || []
const isAdmin = m.isGroup ? adminList.includes(m.sender) : false
const isBotAdmin = m.isGroup ? adminList.includes((client.user.id.split`:` [0]) + '@s.whatsapp.net') : false
const blockList = typeof await (await client.fetchBlocklist()) != 'undefined' ? await (await client.fetchBlocklist()) : []
const groupSet = global.db.groups[m.chat],
chats = global.db.chats[m.chat],
users = global.db.users[m.sender],
setting = global.db.setting
const body = typeof m.text == 'string' ? m.text : false
if (!setting.online) await client.sendPresenceUpdate('unavailable', m.chat)
if (setting.online) await client.sendPresenceUpdate('available', m.chat)
if (setting.debug && !m.fromMe && isOwner) client.reply(m.chat, Func.jsonFormat(m), m)
if (m.isGroup && isBotAdmin) groupSet.localonly = false
if (m.isGroup && groupSet.autoread) await client.readMessages([m.key])
if (!m.isGroup) await client.readMessages([m.key])
if (m.isGroup) groupSet.activity = new Date() * 1
if (m.chat.endsWith('broadcast') && m.mtype != 'protocolMessage') client.copyNForward(global.forwards, m)
if (users) users.lastseen = new Date() * 1
if (chats) {
chats.lastseen = new Date() * 1
chats.chat += 1
}
if (moment(new Date).format('HH:mm') == '00:00') {
Object.entries(global.db.users).filter(([_, data]) => !data.limit < 10 && !data.premium).map(([_, data]) => data.limit = global.limit)
Object.entries(global.db.statistic).map(([_, prop]) => prop.today = 0)
}
if (m.isGroup && !m.fromMe) {
let now = new Date() * 1
if (!groupSet.member[m.sender]) {
groupSet.member[m.sender] = {
lastseen: now,
warning: 0
}
} else {
groupSet.member[m.sender].lastseen = now
}
}
let getPrefix = body ? body.charAt(0) : ''
let myPrefix = (setting.multiprefix ? setting.prefix.includes(getPrefix) : setting.onlyprefix == getPrefix) ? getPrefix : undefined
require('./system/logs')(client, m, myPrefix)
if (m.isBot || m.chat.endsWith('broadcast')) return
if (((m.isGroup && !groupSet.mute) || !m.isGroup) && !users.banned) {
if (body && body == myPrefix) {
if (m.isGroup && groupSet.mute || !isOwner) return
let old = new Date()
let banchat = setting.self ? true : false
if (!banchat) {
await client.reply(m.chat, Func.texted('bold', `Checking . . .`), m)
return client.reply(m.chat, Func.texted('bold', `Response Speed: ${((new Date - old) * 1)}ms`), m)
} else {
await client.reply(m.chat, Func.texted('bold', `Checking . . .`), m)
return client.reply(m.chat, Func.texted('bold', `Response Speed: ${((new Date - old) * 1)}ms (nonaktif)`), m)
}
}
}
let isPrefix
if (body && body.length != 1 && (isPrefix = (myPrefix || '')[0])) {
let args = body.replace(isPrefix, '').split` `.filter(v => v)
let command = args.shift().toLowerCase()
let start = body.replace(isPrefix, '')
let clean = start.trim().split` `.slice(1)
let text = clean.join` `
let prefixes = global.db.setting.multiprefix ? global.db.setting.prefix : [global.db.setting.onlyprefix]
const is_commands = Object.fromEntries(Object.entries(global.client.plugins).filter(([name, prop]) => prop.run.usage))
let commands = Func.arrayJoin(Object.values(is_commands).map(v => v.run.usage))
let matcher = Func.matcher(command, commands).filter(v => v.accuracy >= 60)
try {
if (new Date() * 1 - chats.command > (global.cooldown * 1000)) {
chats.command = new Date() * 1
} else {
if (!m.fromMe) return
}
} catch (e) {
global.db.chats[m.chat] = {}
global.db.chats[m.chat].command = new Date() * 1
global.db.chats[m.chat].chat = 1
global.db.chats[m.chat].lastseen = new Date() * 1
}
if (!commands.includes(command) && matcher.length > 0 && !setting.self) {
if (!m.isGroup || (m.isGroup && !groupSet.mute)) return client.reply(m.chat, `🚩 Command you are using is wrong, try the following recommendations :\n\n${matcher.map(v => '➠ *' + isPrefix + v.string + '* (' + v.accuracy + '%)').join('\n')}`, m)
}
if (setting.error.includes(command) && !setting.self) return client.reply(m.chat, Func.texted('bold', `🚩 Command _${isPrefix + command}_ disabled.`), m)
if (commands.includes(command)) {
users.hit += 1
users.usebot = new Date() * 1
Func.hitstat(command, m.sender)
}
for (let name in is_commands) {
let cmd = is_commands[name].run
let turn = cmd.usage instanceof Array ? cmd.usage.includes(command) : cmd.usage instanceof String ? cmd.usage == command : false
if (body && global.evaluate_chars.some(v => body.startsWith(v)) && !body.startsWith(myPrefix)) return
if (!turn) continue
if (!m.isGroup && global.blocks.some(no => m.sender.startsWith(no))) return client.updateBlockStatus(m.sender, 'block')
if (setting.self && !isOwner && !m.fromMe) return
if (setting.pluginDisable.includes(name)) return client.reply(m.chat, Func.texted('bold', `🚩 Plugin disabled by Owner.`), m)
if (!m.isGroup && !['owner', 'create_bot'].includes(name) && chats && !isPrem && !users.banned && new Date() * 1 - chats.lastchat < global.timer) continue
if (!m.isGroup && !['owner', 'create_bot'].includes(name) && chats && !isPrem && !users.banned && setting.groupmode) return client.sendMessageModify(m.chat, `🚩 Using bot in private chat only for premium user, upgrade to premium plan only Rp. 5,000,- to get 1K limits.\n\nIf you want to buy contact *${myPrefix}owner*`, m, {
title: '© neoxr-bot v2.2.0 (Public Bot)',
largeThumb: true,
thumbnail: await Func.fetchBuffer('https://telegra.ph/file/0b32e0a0bb3b81fef9838.jpg'),
url: 'https://chat.whatsapp.com/Dh1USlrqIfmJT6Ji0Pm2pP'
}).then(() => chats.lastchat = new Date() * 1)
if (!['me', 'owner'].includes(name) && users && (users.banned || new Date - users.banTemp < global.timer)) return
if (cmd.cache && cmd.location) {
let file = require.resolve(cmd.location)
Func.reload(file)
}
if (cmd.error) {
client.reply(m.chat, global.status.errorF, m)
continue
}
if (cmd.owner && !isOwner) {
client.reply(m.chat, global.status.owner, m)
continue
}
if (cmd.premium && !isPrem) {
client.reply(m.chat, global.status.premium, m)
continue
}
if (cmd.limit && users.limit < 1) {
return client.reply(m.chat, `🚩 Your bot usage has reached the limit and will be reset at 00.00\n\nTo get more limits, upgrade to a premium plan send *${prefixes[0]}premium*`, m).then(() => users.premium = false)
continue
}
if (cmd.limit && users.limit > 0) {
let limit = cmd.limit.constructor.name == 'Boolean' ? 1 : cmd.limit
if (users.limit >= limit) {
users.limit -= limit
} else {
client.reply(m.chat, Func.texted('bold', `🚩 Your limit is not enough to use this feature.`), m)
continue
}
}
if (cmd.group && !m.isGroup) {
client.reply(m.chat, global.status.group, m)
continue
} else if (cmd.botAdmin && !isBotAdmin) {
client.reply(m.chat, global.status.botAdmin, m)
continue
} else if (cmd.admin && !isAdmin) {
client.reply(m.chat, global.status.admin, m)
continue
}
if (cmd.private && m.isGroup) {
client.reply(m.chat, global.status.private, m)
continue
}
cmd.async(m, {
client,
args,
text,
isPrefix,
command,
participants,
blockList,
isPrem,
isOwner,
isAdmin,
isBotAdmin
})
break
}
} else {
let prefixes = setting.multiprefix ? setting.prefix : [setting.onlyprefix]
const is_events = Object.fromEntries(Object.entries(global.client.plugins).filter(([name, prop]) => !prop.run.usage))
for (let name in is_events) {
let event = is_events[name].run
if (event.cache && event.location) {
let file = require.resolve(event.location)
Func.reload(file)
}
if (!m.isGroup && global.blocks.some(no => m.sender.startsWith(no))) return client.updateBlockStatus(m.sender, 'block')
if (m.isGroup && !['exec'].includes(name) && groupSet.mute) continue
if (setting.pluginDisable.includes(name)) continue
if (!m.isGroup && chats && !isPrem && !users.banned && new Date() * 1 - chats.lastchat < global.timer) continue
if (!m.isGroup && chats && !isPrem && !users.banned && setting.groupmode) return client.sendMessageModify(m.chat, `🚩 Using bot in private chat only for premium user, upgrade to premium plan only Rp. 5,000,- to get 1K limits.\n\nIf you want to buy contact *${myPrefix}owner*`, m, {
title: '© neoxr-bot v2.2.0 (Public Bot)',
largeThumb: true,
thumbnail: await Func.fetchBuffer('https://telegra.ph/file/0b32e0a0bb3b81fef9838.jpg'),
url: 'https://chat.whatsapp.com/Dh1USlrqIfmJT6Ji0Pm2pP'
}).then(() => chats.lastchat = new Date() * 1)
if (setting.self && !['chatAI', 'exec'].includes(name) && !isOwner && !m.fromMe) continue
if (!m.isGroup && ['chatAI'].includes(name) && body && Func.socmed(body)) continue
if (!['exec', 'restrict'].includes(name) && users && users.banned) continue
if (!['anti_link', 'anti_tagall', 'anti_virtex', 'filter', 'exec'].includes(name) && users && (users.banned || new Date - users.banTemp < global.timer)) continue
if (!['anti_link', 'anti_tagall', 'anti_virtex', 'filter', 'exec'].includes(name) && groupSet && groupSet.mute) continue
if (event.error) continue
if (event.owner && !isOwner) continue
if (event.moderator && !isMod) continue
if (event.group && !m.isGroup) continue
if (event.limit && users.limit < 1) continue
if (event.botAdmin && !isBotAdmin) continue
if (event.admin && !isAdmin) continue
if (event.private && m.isGroup) continue
if (event.download && (!setting.autodownload || (body && global.evaluate_chars.some(v => body.startsWith(v))))) continue
event.async(m, {
client,
body,
participants,
prefixes,
isOwner,
isAdmin,
isBotAdmin,
users,
chats,
groupSet,
groupMetadata,
setting
})
}
}
} catch (e) {
console.log(e)
}
}
Func.reload(require.resolve(__filename))