Repository navigation
Expand file tree
/
Copy pathhandler.js
More file actions
195 lines (176 loc) · 5.81 KB
/
Copy pathhandler.js
File metadata and controls
195 lines (176 loc) · 5.81 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
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
import axios from 'axios'
import {
jidNormalizedUser
} from 'baileys'
import util from 'util'
import cp from 'child_process'
import cron from 'node-cron';
import moment from 'moment-timezone';
import Api from '#lib/api.js'
import Func from '#lib/function.js'
import log from '#lib/logger.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 || cfg.bot.owner.includes(m.sender.split('@')[0])
await db.main(m)
if (m.isBot) return
if (!isOwner && db.list().settings.self) return;
// 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;
// Ambil metadata grup atau set null untuk private message
const metadata = m.isGroup ?
conn.chats[m.chat] || (await conn.groupMetadata(m.chat).catch(() => null)) :
null; // Gak perlu group metadata untuk private message
// Cek kalau lagi di grup dan metadata participants-nya gak ada
if (m.isGroup && !metadata?.participants) {
console.error("⚠️ Metadata participants tidak ditemukan, bukan grup atau metadata belum ke-load");
return;
}
// Ambil data pengirim dan bot
let senderData = m.isGroup ?
metadata.participants.find(u => conn.getJid(u.id) === m.sender) :
{
id: m.sender
}; // Default sender data untuk private message
let botData = m.isGroup ?
metadata.participants.find(u => conn.getJid(u.id) === jidNormalizedUser(conn.user.id)) :
{
id: jidNormalizedUser(conn.user.id)
}; // Default bot data untuk private message
let isAdmin = m.isGroup && senderData && senderData.admin === 'admin';
let isBotAdmin = m.isGroup && botData && botData.admin === 'admin';
// Untuk private message, kamu bisa set admin dan botAdmin sesuai kebutuhan
if (!m.isGroup) {
isAdmin = false; // Misalnya bot gak punya role admin di private message
isBotAdmin = true; // Misalnya bot selalu dianggap admin di private message
}
const Scrape = await scrape.list();
const isPrems = db.list().user[m.sender].premium.status;
const isBans = db.list().user[m.sender].banned.status;
cron.schedule("* * * * *", () => {
let user = Object.keys(db.list().user);
let time = moment.tz("Asia/Jakarta").format("HH:mm");
if (db.list().settings.resetlimit == time) {
for (let i of user) {
db.list().user[i].limit = 100;
}
}
});
const ctx = {
Api,
Func,
downloadM,
quoted,
metadata,
isOwner,
isAdmin,
isBotAdmin,
isPrems,
isBans,
log,
Scrape
}
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(cfg.mess.owner)
continue
}
if (plugin.settings?.private && m.isGroup) {
m.reply(cfg.mess.private)
continue
}
if (plugin.settings?.group && !m.isGroup) {
m.reply(cfg.mess.group)
continue
}
if (plugin.settings?.admin && !isAdmin) {
m.reply(cfg.mess.admin)
continue
}
if (plugin.settings?.botAdmin && !isBotAdmin) {
m.reply(cfg.mess.botAdmin)
continue
}
if (plugin.settings?.premium && !isPrems) {
m.reply(cfg.mess.premium)
continue
}
if (plugin.settings?.free && isPrems) {
m.reply(cfg.mess.free)
continue
}
if (plugin.settings?.loading) m.reply(cfg.mess.wait)
plugin.run(conn, m, ctx)
.then(async (a) => {
if (plugin.settings?.limit && !isPrems && !isOwner) {
db.list().user[m.sender].limit -= 1;
let info = `Halo kak!, Kamu baru aja pkek fitur limit 😄
Sekarang limit kakk tersisa (${db.list().user[m.sender].limit} Limit) kak.
limit bakal tereset tiap jam 2:00 WIB kak!`;
m.reply(info);
}
})
}
} catch (e) {
console.error(`[PLUGIN ERROR] ${plugin.name}`, Func.jsonFormat(e))
await m.reply('Terjadi error saat menjalankan command.')
} finally {
if (db.list().settings.online) {
await conn.readMessages([m.key]);
}
}
}
}
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)
}
}
}