File size: 9,510 Bytes
f7e1fa7 |
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 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
let activeCmd = false;
module.exports = function ({ api, models, Users, Threads, Currencies, ...rest }) {
const stringSimilarity = require("string-similarity");
const moment = require("moment-timezone");
const logger = require("../../utils/log");
return async function ({ event, ...rest2 }) {
if (activeCmd) {
return;
}
const dateNow = Date.now();
const time = moment.tz("Asia/Manila").format("HH:MM:ss DD/MM/YYYY");
const { allowInbox, PREFIX, ADMINBOT, DeveloperMode, adminOnly } = global.config;
const { userBanned, threadBanned, threadInfo, threadData, commandBanned } = global.data;
const { commands, cooldowns } = global.client;
var { body, senderID, threadID, messageID } = event;
var senderID = String(senderID),
threadID = String(threadID);
const threadSetting = threadData.get(threadID) || {};
const args = (body || "").trim().split(/ +/);
const commandName = args.shift()?.toLowerCase();
var command = commands.get(commandName);
const replyAD = "[ MODE ] - Only bot admin can use bot";
if (
command &&
command.config.name.toLowerCase() === commandName.toLowerCase() &&
!ADMINBOT.includes(senderID) &&
adminOnly &&
senderID !== api.getCurrentUserID()
) {
return api.sendMessage(replyAD, threadID, messageID);
}
if (
typeof body === "string" &&
body.startsWith(PREFIX) &&
!ADMINBOT.includes(senderID) &&
adminOnly &&
senderID !== api.getCurrentUserID()
) {
return api.sendMessage(replyAD, threadID, messageID);
}
if (
userBanned.has(senderID) ||
threadBanned.has(threadID) ||
(allowInbox == ![] && senderID == threadID)
) {
if (!ADMINBOT.includes(senderID.toString())) {
if (userBanned.has(senderID)) {
const { reason, dateAdded } = userBanned.get(senderID) || {};
return api.sendMessage(
global.getText("handleCommand", "userBanned", reason, dateAdded),
threadID,
async (err, info) => {
await new Promise((resolve) => setTimeout(resolve, 5 * 1000));
return api.unsendMessage(info.messageID);
},
messageID,
);
} else {
if (threadBanned.has(threadID)) {
const { reason, dateAdded } = threadBanned.get(threadID) || {};
return api.sendMessage(
global.getText(
"handleCommand",
"threadBanned",
reason,
dateAdded,
),
threadID,
async (err, info) => {
await new Promise((resolve) => setTimeout(resolve, 5 * 1000));
return api.unsendMessage(info.messageID);
},
messageID,
);
}
}
}
}
if (commandName.startsWith(PREFIX)) {
if (!command) {
const allCommandName = Array.from(commands.keys());
const checker = stringSimilarity.findBestMatch(
commandName,
allCommandName,
);
if (checker.bestMatch.rating >= 0.5) {
command = commands.get(checker.bestMatch.target);
} else {
return api.setMessageReaction("❓", event.messageID, () => {}, true);
}
}
}
if (commandBanned.get(threadID) || commandBanned.get(senderID)) {
if (!ADMINBOT.includes(senderID)) {
const banThreads = commandBanned.get(threadID) || [],
banUsers = commandBanned.get(senderID) || [];
if (banThreads.includes(command.config.name))
return api.sendMessage(
global.getText(
"handleCommand",
"commandThreadBanned",
command.config.name,
),
threadID,
async (err, info) => {
await new Promise((resolve) => setTimeout(resolve, 5 * 1000));
return api.unsendMessage(info.messageID);
},
messageID,
);
if (banUsers.includes(command.config.name))
return api.sendMessage(
global.getText(
"handleCommand",
"commandUserBanned",
command.config.name,
),
threadID,
async (err, info) => {
await new Promise((resolve) => setTimeout(resolve, 5 * 1000));
return api.unsendMessage(info.messageID);
},
messageID,
);
}
}
if (command && command.config && command.config.usePrefix !== undefined) {
command.config.usePrefix = command.config.usePrefix ?? true;
}
if (command && command.config) {
if (
command.config.usePrefix === false &&
commandName.toLowerCase() !== command.config.name.toLowerCase() &&
!command.config.allowPrefix
) {
api.sendMessage(
global.getText("handleCommand", "notMatched", command.config.name),
event.threadID,
event.messageID,
);
return;
}
if (command.config.usePrefix === true && !body.startsWith(PREFIX)) {
return;
}
}
if (command && command.config) {
if (typeof command.config.usePrefix === "undefined") {
api.sendMessage(
global.getText("handleCommand", "noPrefix", command.config.name),
event.threadID,
event.messageID,
);
return;
}
}
if (
command &&
command.config &&
command.config.commandCategory &&
command.config.commandCategory.toLowerCase() === "nsfw" &&
!global.data.threadAllowNSFW.includes(threadID) &&
!ADMINBOT.includes(senderID)
)
return api.sendMessage(
global.getText("handleCommand", "threadNotAllowNSFW"),
threadID,
async (err, info) => {
await new Promise((resolve) => setTimeout(resolve, 5 * 1000));
return api.unsendMessage(info.messageID);
},
messageID,
);
var threadInfo2;
if (event.isGroup == !![])
try {
threadInfo2 =
threadInfo.get(threadID) || (await Threads.getInfo(threadID));
if (Object.keys(threadInfo2).length == 0) throw new Error();
} catch (err) {
logger.log(
global.getText("handleCommand", "cantGetInfoThread", "error"),
);
}
var permssion = 0;
var threadInfoo =
threadInfo.get(threadID) || (await Threads.getInfo(threadID));
const find = threadInfoo.adminIDs.find((el) => el.id == senderID);
if (ADMINBOT.includes(senderID.toString())) permssion = 2;
else if (!ADMINBOT.includes(senderID) && find) permssion = 1;
if (
command &&
command.config &&
command.config.hasPermssion &&
command.config.hasPermssion > permssion
) {
return api.sendMessage(
global.getText(
"handleCommand",
"permissionNotEnough",
command.config.name,
),
event.threadID,
event.messageID,
);
}
if (
command &&
command.config &&
!client.cooldowns.has(command.config.name)
) {
client.cooldowns.set(command.config.name, new Map());
}
const timestamps =
command && command.config
? client.cooldowns.get(command.config.name)
: undefined;
const expirationTime =
((command && command.config && command.config.cooldowns) || 1) * 1000;
if (
timestamps &&
timestamps instanceof Map &&
timestamps.has(senderID) &&
dateNow < timestamps.get(senderID) + expirationTime
) {
const cooldowns = ((timestamps.get(senderID) + expirationTime - dateNow) / 1000).toFixed(1);
return api.sendMessage(`The command "${command.config.name}" has been cooldown in ${cooldowns} seconds before you can use it again.`, event.threadID, event.messageID);
}
var getText2;
if (
command &&
command.languages &&
typeof command.languages === "object" &&
command.languages.hasOwnProperty(global.config.language)
)
getText2 = (...values) => {
var lang = command.languages[global.config.language][values[0]] || "";
for (var i = values.length; i > 0x2533 + 0x1105 + -0x3638; i--) {
const expReg = RegExp("%" + i, "g");
lang = lang.replace(expReg, values[i]);
}
return lang;
};
else getText2 = () => {};
try {
const Obj = {
...rest,
...rest2,
api: api,
event: event,
args: args,
models: models,
Users: Users,
Threads: Threads,
Currencies: Currencies,
permssion: permssion,
getText: getText2,
};
if (command && typeof command.run === "function") {
command.run(Obj);
timestamps.set(senderID, dateNow);
if (DeveloperMode == !![]) {
logger.log(
global.getText(
"handleCommand",
"executeCommand",
time,
commandName,
senderID,
threadID,
args.join(" "),
Date.now() - dateNow,
),
"DEV MODE",
);
}
return;
}
} catch (e) {
return api.sendMessage(
global.getText("handleCommand", "commandError", commandName, e),
threadID,
);
}
activeCmd = false;
};
};
|