-
-
Notifications
You must be signed in to change notification settings - Fork 343
/
Copy pathhandler.js
239 lines (235 loc) · 15 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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
const { Function: Func, Scraper, Cooldown, Spam, InvCloud, Config: env } = new (require('@neoxr/wb'))
const cron = require('node-cron')
const cooldown = new Cooldown(env.cooldown)
const spam = new Spam({
RESET_TIMER: env.cooldown,
HOLD_TIMER: env.timeout,
PERMANENT_THRESHOLD: env.permanent_threshold,
NOTIFY_THRESHOLD: env.notify_threshold,
BANNED_THRESHOLD: env.banned_threshold
})
module.exports = async (client, ctx) => {
var { store, m, body, prefix, plugins, commands, args, command, text, prefixes, core } = ctx
try {
// "InvCloud" reduces RAM usage and minimizes errors during rewrite (according to recommendations/suggestions from Baileys)
require('./lib/system/schema')(m, env), InvCloud(store)
const groupSet = global.db.groups.find(v => v.jid === m.chat)
const chats = global.db.chats.find(v => v.jid === m.chat)
const users = global.db.users.find(v => v.jid === m.sender)
const setting = global.db.setting
const isOwner = [client.decodeJid(client.user.id).replace(/@.+/, ''), env.owner, ...setting.owners].map(v => v + '@s.whatsapp.net').includes(m.sender)
const isPrem = users && users.premium || isOwner
const groupMetadata = m.isGroup ? await Func.getGroupMetadata(m.chat, client) : {}
const participants = m.isGroup ? groupMetadata ? 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 isSpam = spam.detection(client, m, {
prefix, command, commands, users, cooldown,
show: 'all', // choose 'all' or 'command-only'
banned_times: users.ban_times,
simple: false
})
// exception disabled plugin
var plugins = Object.fromEntries(Object.entries(plugins).filter(([name, _]) => !setting.pluginDisable.includes(name)))
// stories reaction
client.storyJid = client.storyJid ? client.storyJid : []
if (m.chat.endsWith('broadcast') && !client.storyJid.includes(m.sender) && m.sender != client.decodeJid(client.user.id)) client.storyJid.push(m.sender)
if (m.chat.endsWith('broadcast') && [...new Set(client.storyJid)].includes(m.sender) && !/protocol/.test(m.mtype)) {
await client.sendMessage('status@broadcast', {
react: {
text: Func.random(['🤣', '🥹', '😂', '😋', '😎', '🤓', '🤪', '🥳', '😠', '😱', '🤔']),
key: m.key
}
}, {
statusJidList: [m.sender]
})
}
if (!setting.online) client.sendPresenceUpdate('unavailable', m.chat)
if (setting.online) {
client.sendPresenceUpdate('available', m.chat)
client.readMessages([m.key])
}
if (m.isGroup && !isBotAdmin) {
groupSet.localonly = false
}
if (!users || typeof users.limit === undefined) return global.db.users.push({
jid: m.sender,
banned: false,
limit: env.limit,
hit: 0,
spam: 0
})
if (!setting.multiprefix) setting.noprefix = false
if (setting.debug && !m.fromMe && isOwner) client.reply(m.chat, Func.jsonFormat(m), m)
if (m.isGroup && !groupSet.stay && (new Date * 1) >= groupSet.expired && groupSet.expired != 0) {
return client.reply(m.chat, Func.texted('italic', '🚩 Bot time has expired and will leave from this group, thank you.', null, {
mentions: participants.map(v => v.id)
})).then(async () => {
groupSet.expired = 0
await Func.delay(2000).then(() => client.groupLeave(m.chat))
})
}
if (users && (new Date * 1) >= users.expired && users.expired != 0) {
return client.reply(users.jid, Func.texted('italic', '🚩 Your premium package has expired, thank you for buying and using our service.')).then(async () => {
users.premium = false
users.expired = 0
users.limit = env.limit
})
}
if (m.isGroup) groupSet.activity = new Date() * 1
if (users) {
users.name = m.pushName
users.lastseen = new Date() * 1
}
if (chats) {
chats.chat += 1
chats.lastseen = new Date * 1
}
if (m.isGroup && !m.isBot && users && users.afk > -1) {
client.reply(m.chat, `You are back online after being offline for : ${Func.texted('bold', Func.toTime(new Date - users.afk))}\n\n• ${Func.texted('bold', 'Reason')}: ${users.afkReason ? users.afkReason : '-'}`, m)
users.afk = -1
users.afkReason = ''
}
cron.schedule('00 00 * * *', () => {
setting.lastReset = new Date * 1
global.db.users.filter(v => v.limit < env.limit && !v.premium).map(v => v.limit = env.limit)
Object.entries(global.db.statistic).map(([_, prop]) => prop.today = 0)
}, {
scheduled: true,
timezone: process.env.TZ
})
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
}
}
if (setting.antispam && isSpam && /(BANNED|NOTIFY|TEMPORARY)/.test(isSpam.state)) return client.reply(m.chat, Func.texted('bold', `🚩 ${isSpam.msg}`), m)
if (setting.antispam && isSpam && /HOLD/.test(isSpam.state)) return
// if (body && !setting.self && !setting.noprefix && !core.corePrefix.includes(core.prefix) && commands.includes(core.command) && !env.evaluate_chars.includes(core.command)) return client.reply(m.chat, `🚩 *Prefix needed!*, this bot uses prefix : *[ ${setting.multiprefix ? setting.prefix.join(', ') : setting.onlyprefix} ]*\n\n➠ ${setting.multiprefix ? setting.prefix[0] : setting.onlyprefix}${core.command} ${text || ''}`, m)
if (body && !setting.self && core.prefix != setting.onlyprefix && commands.includes(core.command) && !setting.multiprefix && !env.evaluate_chars.includes(core.command)) return client.reply(m.chat, `🚩 *Incorrect prefix!*, this bot uses prefix : *[ ${setting.onlyprefix} ]*\n\n➠ ${setting.onlyprefix + core.command} ${text || ''}`, m)
const matcher = Func.matcher(command, commands).filter(v => v.accuracy >= 60)
if (prefix && !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 => '➠ *' + (prefix ? prefix : '') + v.string + '* (' + v.accuracy + '%)').join('\n')}`, m)
}
if (body && prefix && commands.includes(command) || body && !prefix && commands.includes(command) && setting.noprefix || body && !prefix && commands.includes(command) && env.evaluate_chars.includes(command)) {
if (setting.error.includes(command)) return client.reply(m.chat, Func.texted('bold', `🚩 Command _${(prefix ? prefix : '') + command}_ disabled.`), m)
if (!m.isGroup && env.blocks.some(no => m.sender.startsWith(no))) return client.updateBlockStatus(m.sender, 'block')
if (commands.includes(command)) {
users.hit += 1
users.usebot = new Date() * 1
Func.hitstat(command, m.sender)
}
const is_commands = Object.fromEntries(Object.entries(plugins).filter(([name, prop]) => prop.run.usage))
for (let name in is_commands) {
const cmd = is_commands[name].run
const turn = cmd.usage instanceof Array ? cmd.usage.includes(command) : cmd.usage instanceof String ? cmd.usage == command : false
const turn_hidden = cmd.hidden instanceof Array ? cmd.hidden.includes(command) : cmd.hidden instanceof String ? cmd.hidden == command : false
if (!turn && !turn_hidden) continue
if (m.isBot || m.chat.endsWith('broadcast') || /edit/.test(m.mtype)) continue
if (setting.self && !isOwner && !m.fromMe) continue
if (!m.isGroup && !['owner'].includes(name) && chats && !isPrem && !users.banned && new Date() * 1 - chats.lastchat < env.timeout) continue
if (!m.isGroup && !['owner', 'menfess', 'scan', 'verify', 'payment', 'premium'].includes(name) && chats && !isPrem && !users.banned && setting.groupmode) {
client.sendMessageModify(m.chat, `⚠️ Using bot in private chat only for premium user, want to upgrade to premium plan ? send *${prefixes[0]}premium* to see benefit and prices.`, m, {
largeThumb: true,
thumbnail: 'https://telegra.ph/file/0b32e0a0bb3b81fef9838.jpg',
url: setting.link
}).then(() => chats.lastchat = new Date() * 1)
continue
}
if (!['me', 'owner', 'exec'].includes(name) && users && (users.banned || new Date - users.ban_temporary < env.timeout)) continue
if (m.isGroup && !['activation', 'groupinfo'].includes(name) && groupSet.mute) continue
if (cmd.cache && cmd.location) {
Func.updateFile(cmd.location)
}
if (cmd.owner && !isOwner) {
client.reply(m.chat, global.status.owner, m)
continue
}
if (cmd.restrict && !isPrem && !isOwner && text && new RegExp('\\b' + setting.toxic.join('\\b|\\b') + '\\b').test(text.toLowerCase())) {
client.reply(m.chat, `⚠️ You violated the *Terms & Conditions* of using bots by using blacklisted keywords, as a penalty for your violation being blocked and banned.`, m).then(() => {
users.banned = true
client.updateBlockStatus(m.sender, 'block')
})
continue
}
if (cmd.premium && !isPrem) {
client.reply(m.chat, global.status.premium, m)
continue
}
if (cmd.limit && users.limit < 1) {
client.reply(m.chat, `⚠️ You reached the limit and will be reset at 00.00\n\nTo get more limits upgrade to premium plans.`, m).then(() => users.premium = false)
continue
}
if (cmd.limit && users.limit > 0) {
const 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: prefix, prefixes, command, groupMetadata, participants, users, chats, groupSet, setting, isOwner, isAdmin, isBotAdmin, plugins: Object.fromEntries(Object.entries(plugins).filter(([name, _]) => !setting.pluginDisable.includes(name))), blockList, env, ctx, store, Func, Scraper })
break
}
} else {
const is_events = Object.fromEntries(Object.entries(plugins).filter(([name, prop]) => !prop.run.usage))
for (let name in is_events) {
let event = is_events[name].run
if ((m.fromMe && m.isBot) || m.chat.endsWith('broadcast') || /pollUpdate/.test(m.mtype)) continue
if (!m.isGroup && env.blocks.some(no => m.sender.startsWith(no))) return client.updateBlockStatus(m.sender, 'block')
if (setting.self && !['menfess_ev', 'anti_link', 'anti_tagall', 'anti_virtex', 'filter'].includes(event.pluginName) && !isOwner && !m.fromMe) continue
if (!['anti_link', 'anti_tagall', 'anti_virtex', 'filter'].includes(name) && users && (users.banned || new Date - users.ban_temporary < env.timeout)) continue
if (!['anti_link', 'anti_tagall', 'anti_virtex', 'filter'].includes(name) && groupSet && groupSet.mute) continue
if (!m.isGroup && !['menfess_ev', 'chatbot', 'auto_download'].includes(name) && chats && !isPrem && !users.banned && new Date() * 1 - chats.lastchat < env.timeout) continue
if (!m.isGroup && setting.groupmode && !['system_ev', 'menfess_ev', 'chatbot', 'auto_download'].includes(name) && !isPrem) return client.sendMessageModify(m.chat, `⚠️ Using bot in private chat only for premium user, want to upgrade to premium plan ? send *${prefixes[0]}premium* to see benefit and prices.`, m, {
largeThumb: true,
thumbnail: await Func.fetchBuffer('https://telegra.ph/file/0b32e0a0bb3b81fef9838.jpg'),
url: setting.link
}).then(() => chats.lastchat = new Date() * 1)
if (event.cache && event.location) {
Func.updateFile(event.location)
}
if (event.error) continue
if (event.owner && !isOwner) continue
if (event.group && !m.isGroup) continue
if (event.limit && !event.game && users.limit < 1 && body && Func.generateLink(body) && Func.generateLink(body).some(v => Func.socmed(v))) return client.reply(m.chat, `⚠️ You reached the limit and will be reset at 00.00\n\nTo get more limits upgrade to premium plan.`, m).then(() => {
users.premium = false
users.expired = 0
})
if (event.botAdmin && !isBotAdmin) continue
if (event.admin && !isAdmin) continue
if (event.private && m.isGroup) continue
if (event.download && (!setting.autodownload || (body && env.evaluate_chars.some(v => body.startsWith(v))))) continue
event.async(m, { client, body, prefixes, groupMetadata, participants, users, chats, groupSet, setting, isOwner, isAdmin, isBotAdmin, plugins: Object.fromEntries(Object.entries(plugins).filter(([name, _]) => !setting.pluginDisable.includes(name))), blockList, env, ctx, store, Func, Scraper })
}
}
} catch (e) {
if (/(undefined|overlimit|timed|timeout|users|item|time)/ig.test(e.message)) return
console.log(e)
if (!m.fromMe) return m.reply(Func.jsonFormat(new Error('neoxr-bot encountered an error :' + e)))
}
Func.reload(require.resolve(__filename))
}