forked from AgusXzz/ESEMPE-MD
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler.js
More file actions
116 lines (104 loc) · 3.21 KB
/
handler.js
File metadata and controls
116 lines (104 loc) · 3.21 KB
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
import axios from 'axios'
import { jidNormalizedUser } from 'baileys'
import util from 'util'
import cp from 'child_process'
import Api from '#lib/api.js'
import Func from '#lib/function.js'
export default async function Command(conn, m) {
const quoted = m.isQuoted ? m.quoted : m
const downloadM = async (filename) => await conn.downloadMediaMessage(quoted, filename)
const isCommand = (m.prefix && m.body.startsWith(m.prefix)) || false
const isOwner = m.fromMe || ownerNumber.includes(m.sender.split('@')[0])
if (m.isBot) return
if (!pubelik && !isOwner) return
const metadata = m.isGroup ? conn.chats[m.chat] || (await conn.groupMetadata(m.chat).catch(() => null)) : {}
const isAdmin = m.isGroup && metadata.participants.find(u => conn.getJid(u.id) === m.sender)?.admin == 'admin' || false;
const isBotAdmin = m.isGroup && metadata.participants.find(u => conn.getJid(u.id) === jidNormalizedUser(conn.user.id))?.admin == 'admin' || false;
const ctx = {
Api,
Func,
downloadM,
quoted,
metadata,
isOwner,
isAdmin,
isBotAdmin
}
for (const plugin of Object.values(plugins)) {
if (typeof plugin.on === 'function') {
try {
const handled = await plugin.on.call(conn, m, ctx)
if (handled) continue
} catch (e) {
console.error(`[PLUGIN EVENT ERROR] ${plugin.name}`, e)
}
}
if (isCommand) {
const command = m.command?.toLowerCase()
const isCmd =
plugin?.command?.includes(command) ||
(plugin?.alias && plugin.alias.includes(command))
try {
if (isCmd) {
if (plugin.settings?.owner && !isOwner) {
m.reply(mess.owner)
continue
}
if (plugin.settings?.private && m.isGroup) {
m.reply(mess.private)
continue
}
if (plugin.settings?.group && !m.isGroup) {
m.reply(mess.group)
continue
}
if (plugin.settings?.admin && !isAdmin) {
m.reply(mess.admin)
continue
}
if (plugin.settings?.botAdmin && !isBotAdmin) {
m.reply(mess.botAdmin)
continue
}
if (plugin.settings?.loading) m.reply(mess.wait)
plugin.run(conn, m, ctx)
}
} catch (e) {
console.error(`[PLUGIN ERROR] ${plugin.name}`, e)
await m.reply('Terjadi error saat menjalankan command.')
}
}
}
if (['>', '=>'].some((a) => m.body?.toLowerCase().startsWith(a)) && isOwner) {
let evalCmd = ''
try {
evalCmd = /await/i.test(m.text)
? eval(`(async() => { ${m.text} })()`)
: eval(m.text)
} catch (e) {
evalCmd = e
}
new Promise((resolve, reject) => {
try {
resolve(evalCmd)
} catch (err) {
reject(err)
}
})
?.then((res) => m.reply(util.format(res)))
?.catch((err) => m.reply(util.format(err)))
}
if (m.body?.startsWith('$') && isOwner) {
const exec = util.promisify(cp.exec).bind(cp)
let o
try {
o = await exec(m.text)
} catch (e) {
o = e
} finally {
const { stdout, stderr } = o
if (stdout.trim()) m.reply(stdout)
if (stderr.trim()) m.reply(stderr)
}
}
}