Upload 7 files
Browse files
includes/handle/handleCommand.js
ADDED
|
@@ -0,0 +1,311 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
let activeCmd = false;
|
| 2 |
+
|
| 3 |
+
module.exports = function ({ api, models, Users, Threads, Currencies, ...rest }) {
|
| 4 |
+
const stringSimilarity = require("string-similarity");
|
| 5 |
+
const moment = require("moment-timezone");
|
| 6 |
+
const logger = require("../../utils/log");
|
| 7 |
+
|
| 8 |
+
return async function ({ event, ...rest2 }) {
|
| 9 |
+
if (activeCmd) {
|
| 10 |
+
return;
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
const dateNow = Date.now();
|
| 14 |
+
const time = moment.tz("Asia/Manila").format("HH:MM:ss DD/MM/YYYY");
|
| 15 |
+
const { allowInbox, PREFIX, ADMINBOT, DeveloperMode, adminOnly } = global.config;
|
| 16 |
+
const { userBanned, threadBanned, threadInfo, threadData, commandBanned } = global.data;
|
| 17 |
+
const { commands, cooldowns } = global.client;
|
| 18 |
+
|
| 19 |
+
var { body, senderID, threadID, messageID } = event;
|
| 20 |
+
var senderID = String(senderID),
|
| 21 |
+
threadID = String(threadID);
|
| 22 |
+
|
| 23 |
+
const threadSetting = threadData.get(threadID) || {};
|
| 24 |
+
const args = (body || "").trim().split(/ +/);
|
| 25 |
+
const commandName = args.shift()?.toLowerCase();
|
| 26 |
+
var command = commands.get(commandName);
|
| 27 |
+
const replyAD = "[ MODE ] - Only bot admin can use bot";
|
| 28 |
+
|
| 29 |
+
if (
|
| 30 |
+
command &&
|
| 31 |
+
command.config.name.toLowerCase() === commandName.toLowerCase() &&
|
| 32 |
+
!ADMINBOT.includes(senderID) &&
|
| 33 |
+
adminOnly &&
|
| 34 |
+
senderID !== api.getCurrentUserID()
|
| 35 |
+
) {
|
| 36 |
+
return api.sendMessage(replyAD, threadID, messageID);
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
if (
|
| 40 |
+
typeof body === "string" &&
|
| 41 |
+
body.startsWith(PREFIX) &&
|
| 42 |
+
!ADMINBOT.includes(senderID) &&
|
| 43 |
+
adminOnly &&
|
| 44 |
+
senderID !== api.getCurrentUserID()
|
| 45 |
+
) {
|
| 46 |
+
return api.sendMessage(replyAD, threadID, messageID);
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
if (
|
| 50 |
+
userBanned.has(senderID) ||
|
| 51 |
+
threadBanned.has(threadID) ||
|
| 52 |
+
(allowInbox == ![] && senderID == threadID)
|
| 53 |
+
) {
|
| 54 |
+
if (!ADMINBOT.includes(senderID.toString())) {
|
| 55 |
+
if (userBanned.has(senderID)) {
|
| 56 |
+
const { reason, dateAdded } = userBanned.get(senderID) || {};
|
| 57 |
+
return api.sendMessage(
|
| 58 |
+
global.getText("handleCommand", "userBanned", reason, dateAdded),
|
| 59 |
+
threadID,
|
| 60 |
+
async (err, info) => {
|
| 61 |
+
await new Promise((resolve) => setTimeout(resolve, 5 * 1000));
|
| 62 |
+
return api.unsendMessage(info.messageID);
|
| 63 |
+
},
|
| 64 |
+
messageID,
|
| 65 |
+
);
|
| 66 |
+
} else {
|
| 67 |
+
if (threadBanned.has(threadID)) {
|
| 68 |
+
const { reason, dateAdded } = threadBanned.get(threadID) || {};
|
| 69 |
+
return api.sendMessage(
|
| 70 |
+
global.getText(
|
| 71 |
+
"handleCommand",
|
| 72 |
+
"threadBanned",
|
| 73 |
+
reason,
|
| 74 |
+
dateAdded,
|
| 75 |
+
),
|
| 76 |
+
threadID,
|
| 77 |
+
async (err, info) => {
|
| 78 |
+
await new Promise((resolve) => setTimeout(resolve, 5 * 1000));
|
| 79 |
+
return api.unsendMessage(info.messageID);
|
| 80 |
+
},
|
| 81 |
+
messageID,
|
| 82 |
+
);
|
| 83 |
+
}
|
| 84 |
+
}
|
| 85 |
+
}
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
if (commandName.startsWith(PREFIX)) {
|
| 89 |
+
if (!command) {
|
| 90 |
+
const allCommandName = Array.from(commands.keys());
|
| 91 |
+
const checker = stringSimilarity.findBestMatch(
|
| 92 |
+
commandName,
|
| 93 |
+
allCommandName,
|
| 94 |
+
);
|
| 95 |
+
if (checker.bestMatch.rating >= 0.5) {
|
| 96 |
+
command = commands.get(checker.bestMatch.target);
|
| 97 |
+
} else {
|
| 98 |
+
return api.setMessageReaction("❓", event.messageID, () => {}, true);
|
| 99 |
+
}
|
| 100 |
+
}
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
if (commandBanned.get(threadID) || commandBanned.get(senderID)) {
|
| 104 |
+
if (!ADMINBOT.includes(senderID)) {
|
| 105 |
+
const banThreads = commandBanned.get(threadID) || [],
|
| 106 |
+
banUsers = commandBanned.get(senderID) || [];
|
| 107 |
+
if (banThreads.includes(command.config.name))
|
| 108 |
+
return api.sendMessage(
|
| 109 |
+
global.getText(
|
| 110 |
+
"handleCommand",
|
| 111 |
+
"commandThreadBanned",
|
| 112 |
+
command.config.name,
|
| 113 |
+
),
|
| 114 |
+
threadID,
|
| 115 |
+
async (err, info) => {
|
| 116 |
+
await new Promise((resolve) => setTimeout(resolve, 5 * 1000));
|
| 117 |
+
return api.unsendMessage(info.messageID);
|
| 118 |
+
},
|
| 119 |
+
messageID,
|
| 120 |
+
);
|
| 121 |
+
if (banUsers.includes(command.config.name))
|
| 122 |
+
return api.sendMessage(
|
| 123 |
+
global.getText(
|
| 124 |
+
"handleCommand",
|
| 125 |
+
"commandUserBanned",
|
| 126 |
+
command.config.name,
|
| 127 |
+
),
|
| 128 |
+
threadID,
|
| 129 |
+
async (err, info) => {
|
| 130 |
+
await new Promise((resolve) => setTimeout(resolve, 5 * 1000));
|
| 131 |
+
return api.unsendMessage(info.messageID);
|
| 132 |
+
},
|
| 133 |
+
messageID,
|
| 134 |
+
);
|
| 135 |
+
}
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
if (command && command.config && command.config.usePrefix !== undefined) {
|
| 139 |
+
command.config.usePrefix = command.config.usePrefix ?? true;
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
if (command && command.config) {
|
| 143 |
+
if (
|
| 144 |
+
command.config.usePrefix === false &&
|
| 145 |
+
commandName.toLowerCase() !== command.config.name.toLowerCase() &&
|
| 146 |
+
!command.config.allowPrefix
|
| 147 |
+
) {
|
| 148 |
+
api.sendMessage(
|
| 149 |
+
global.getText("handleCommand", "notMatched", command.config.name),
|
| 150 |
+
event.threadID,
|
| 151 |
+
event.messageID,
|
| 152 |
+
);
|
| 153 |
+
return;
|
| 154 |
+
}
|
| 155 |
+
if (command.config.usePrefix === true && !body.startsWith(PREFIX)) {
|
| 156 |
+
return;
|
| 157 |
+
}
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
if (command && command.config) {
|
| 161 |
+
if (typeof command.config.usePrefix === "undefined") {
|
| 162 |
+
api.sendMessage(
|
| 163 |
+
global.getText("handleCommand", "noPrefix", command.config.name),
|
| 164 |
+
event.threadID,
|
| 165 |
+
event.messageID,
|
| 166 |
+
);
|
| 167 |
+
return;
|
| 168 |
+
}
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
if (
|
| 172 |
+
command &&
|
| 173 |
+
command.config &&
|
| 174 |
+
command.config.commandCategory &&
|
| 175 |
+
command.config.commandCategory.toLowerCase() === "nsfw" &&
|
| 176 |
+
!global.data.threadAllowNSFW.includes(threadID) &&
|
| 177 |
+
!ADMINBOT.includes(senderID)
|
| 178 |
+
)
|
| 179 |
+
return api.sendMessage(
|
| 180 |
+
global.getText("handleCommand", "threadNotAllowNSFW"),
|
| 181 |
+
threadID,
|
| 182 |
+
async (err, info) => {
|
| 183 |
+
await new Promise((resolve) => setTimeout(resolve, 5 * 1000));
|
| 184 |
+
return api.unsendMessage(info.messageID);
|
| 185 |
+
},
|
| 186 |
+
messageID,
|
| 187 |
+
);
|
| 188 |
+
|
| 189 |
+
var threadInfo2;
|
| 190 |
+
if (event.isGroup == !![])
|
| 191 |
+
try {
|
| 192 |
+
threadInfo2 =
|
| 193 |
+
threadInfo.get(threadID) || (await Threads.getInfo(threadID));
|
| 194 |
+
if (Object.keys(threadInfo2).length == 0) throw new Error();
|
| 195 |
+
} catch (err) {
|
| 196 |
+
logger.log(
|
| 197 |
+
global.getText("handleCommand", "cantGetInfoThread", "error"),
|
| 198 |
+
);
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
var permssion = 0;
|
| 202 |
+
var threadInfoo =
|
| 203 |
+
threadInfo.get(threadID) || (await Threads.getInfo(threadID));
|
| 204 |
+
const find = threadInfoo.adminIDs.find((el) => el.id == senderID);
|
| 205 |
+
if (ADMINBOT.includes(senderID.toString())) permssion = 2;
|
| 206 |
+
else if (!ADMINBOT.includes(senderID) && find) permssion = 1;
|
| 207 |
+
if (
|
| 208 |
+
command &&
|
| 209 |
+
command.config &&
|
| 210 |
+
command.config.hasPermssion &&
|
| 211 |
+
command.config.hasPermssion > permssion
|
| 212 |
+
) {
|
| 213 |
+
return api.sendMessage(
|
| 214 |
+
global.getText(
|
| 215 |
+
"handleCommand",
|
| 216 |
+
"permissionNotEnough",
|
| 217 |
+
command.config.name,
|
| 218 |
+
),
|
| 219 |
+
event.threadID,
|
| 220 |
+
event.messageID,
|
| 221 |
+
);
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
if (
|
| 225 |
+
command &&
|
| 226 |
+
command.config &&
|
| 227 |
+
!client.cooldowns.has(command.config.name)
|
| 228 |
+
) {
|
| 229 |
+
client.cooldowns.set(command.config.name, new Map());
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
const timestamps =
|
| 233 |
+
command && command.config
|
| 234 |
+
? client.cooldowns.get(command.config.name)
|
| 235 |
+
: undefined;
|
| 236 |
+
|
| 237 |
+
const expirationTime =
|
| 238 |
+
((command && command.config && command.config.cooldowns) || 1) * 1000;
|
| 239 |
+
|
| 240 |
+
if (
|
| 241 |
+
timestamps &&
|
| 242 |
+
timestamps instanceof Map &&
|
| 243 |
+
timestamps.has(senderID) &&
|
| 244 |
+
dateNow < timestamps.get(senderID) + expirationTime
|
| 245 |
+
) {
|
| 246 |
+
const cooldowns = ((timestamps.get(senderID) + expirationTime - dateNow) / 1000).toFixed(1);
|
| 247 |
+
return api.sendMessage(`The command "${command.config.name}" has been cooldown in ${cooldowns} seconds before you can use it again.`, event.threadID, event.messageID);
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
var getText2;
|
| 251 |
+
if (
|
| 252 |
+
command &&
|
| 253 |
+
command.languages &&
|
| 254 |
+
typeof command.languages === "object" &&
|
| 255 |
+
command.languages.hasOwnProperty(global.config.language)
|
| 256 |
+
)
|
| 257 |
+
getText2 = (...values) => {
|
| 258 |
+
var lang = command.languages[global.config.language][values[0]] || "";
|
| 259 |
+
for (var i = values.length; i > 0x2533 + 0x1105 + -0x3638; i--) {
|
| 260 |
+
const expReg = RegExp("%" + i, "g");
|
| 261 |
+
lang = lang.replace(expReg, values[i]);
|
| 262 |
+
}
|
| 263 |
+
return lang;
|
| 264 |
+
};
|
| 265 |
+
else getText2 = () => {};
|
| 266 |
+
|
| 267 |
+
try {
|
| 268 |
+
const Obj = {
|
| 269 |
+
...rest,
|
| 270 |
+
...rest2,
|
| 271 |
+
api: api,
|
| 272 |
+
event: event,
|
| 273 |
+
args: args,
|
| 274 |
+
models: models,
|
| 275 |
+
Users: Users,
|
| 276 |
+
Threads: Threads,
|
| 277 |
+
Currencies: Currencies,
|
| 278 |
+
permssion: permssion,
|
| 279 |
+
getText: getText2,
|
| 280 |
+
};
|
| 281 |
+
|
| 282 |
+
if (command && typeof command.run === "function") {
|
| 283 |
+
command.run(Obj);
|
| 284 |
+
timestamps.set(senderID, dateNow);
|
| 285 |
+
|
| 286 |
+
if (DeveloperMode == !![]) {
|
| 287 |
+
logger.log(
|
| 288 |
+
global.getText(
|
| 289 |
+
"handleCommand",
|
| 290 |
+
"executeCommand",
|
| 291 |
+
time,
|
| 292 |
+
commandName,
|
| 293 |
+
senderID,
|
| 294 |
+
threadID,
|
| 295 |
+
args.join(" "),
|
| 296 |
+
Date.now() - dateNow,
|
| 297 |
+
),
|
| 298 |
+
"DEV MODE",
|
| 299 |
+
);
|
| 300 |
+
}
|
| 301 |
+
return;
|
| 302 |
+
}
|
| 303 |
+
} catch (e) {
|
| 304 |
+
return api.sendMessage(
|
| 305 |
+
global.getText("handleCommand", "commandError", commandName, e),
|
| 306 |
+
threadID,
|
| 307 |
+
);
|
| 308 |
+
}
|
| 309 |
+
activeCmd = false;
|
| 310 |
+
};
|
| 311 |
+
};
|
includes/handle/handleCommandEvent.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
module.exports = function ({ api, models, Users, Threads, Currencies, ...rest }) {
|
| 2 |
+
const logger = require("../../utils/log.js")
|
| 3 |
+
return function ({ event, ...rest2 }) {
|
| 4 |
+
const { allowInbox } = global.config;
|
| 5 |
+
const { userBanned, threadBanned } = global.data;
|
| 6 |
+
const { commands, eventRegistered } = global.client;
|
| 7 |
+
var { senderID, threadID } = event;
|
| 8 |
+
var senderID = String(senderID);
|
| 9 |
+
var threadID = String(threadID);
|
| 10 |
+
if (userBanned.has(senderID) || threadBanned.has(threadID) || allowInbox == !![] && senderID == threadID) return;
|
| 11 |
+
for (const eventReg of eventRegistered) {
|
| 12 |
+
const cmd = commands.get(eventReg);
|
| 13 |
+
var getText2;
|
| 14 |
+
|
| 15 |
+
if (cmd.languages && typeof cmd.languages == 'object')
|
| 16 |
+
getText2 = (...values) => {
|
| 17 |
+
const commandModule = cmd.languages || {};
|
| 18 |
+
if (!commandModule.hasOwnProperty(global.config.language))
|
| 19 |
+
return api.sendMessage(global.getText('handleCommand','notFoundLanguage', cmd.config.name), threadID, messengeID);
|
| 20 |
+
var lang = cmd.languages[global.config.language][values[0]] || '';
|
| 21 |
+
for (var i = values.length; i > 0x16c0 + -0x303 + -0x1f * 0xa3; i--) {
|
| 22 |
+
const expReg = RegExp('%' + i, 'g');
|
| 23 |
+
lang = lang.replace(expReg, values[i]);
|
| 24 |
+
}
|
| 25 |
+
return lang;
|
| 26 |
+
};
|
| 27 |
+
else getText2 = () => {};
|
| 28 |
+
try {
|
| 29 |
+
const Obj = {
|
| 30 |
+
...rest,
|
| 31 |
+
...rest2
|
| 32 |
+
};
|
| 33 |
+
Obj.event = event
|
| 34 |
+
Obj.api = api
|
| 35 |
+
Obj.models = models
|
| 36 |
+
Obj.Users = Users
|
| 37 |
+
Obj.Threads = Threads
|
| 38 |
+
Obj.Currencies = Currencies
|
| 39 |
+
Obj.getText = getText2;
|
| 40 |
+
|
| 41 |
+
if (cmd) cmd.handleEvent(Obj);
|
| 42 |
+
} catch (error) {
|
| 43 |
+
logger.log(global.getText('handleCommandEvent', 'moduleError', cmd.config.name), 'error');
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
};
|
| 47 |
+
};
|
includes/handle/handleCreateDatabase.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
module.exports = function ({ Users, Threads }) {
|
| 2 |
+
const logger =require("../../utils/log.js");
|
| 3 |
+
const threads = require('../database/data/threadsData.json')
|
| 4 |
+
const users = require('../database/data/usersData.json')
|
| 5 |
+
return async function ({ event }) {
|
| 6 |
+
const { allUserID, allThreadID } = global.data;
|
| 7 |
+
const { autoCreateDB } = global.config;
|
| 8 |
+
if (autoCreateDB == ![]) return;
|
| 9 |
+
var { senderID, threadID } = event;
|
| 10 |
+
senderID = String(senderID);
|
| 11 |
+
var threadID = String(threadID);
|
| 12 |
+
try {
|
| 13 |
+
if (!allThreadID.includes(threadID) && event.isGroup == !![] && !threads.hasOwnProperty(threadID)) {
|
| 14 |
+
allThreadID.push(threadID)
|
| 15 |
+
await Threads.createData(threadID);
|
| 16 |
+
logger.log(global.getText('handleCreateDatabase', 'newThread', threadID), 'DATABASE');
|
| 17 |
+
}
|
| 18 |
+
if(threads.hasOwnProperty(threadID)) {
|
| 19 |
+
var data = threads[threadID]
|
| 20 |
+
if(data) {
|
| 21 |
+
if(!data.threadInfo.participantIDs.includes(senderID)) {
|
| 22 |
+
data.threadInfo.participantIDs.push(senderID)
|
| 23 |
+
logger.log('Perform more group data ' + threadID, 'ADD DATA')
|
| 24 |
+
await Threads.setData(threadID, {threadInfo: data.threadInfo})
|
| 25 |
+
}
|
| 26 |
+
}
|
| 27 |
+
}
|
| 28 |
+
if (!allUserID.includes(senderID) && !users.hasOwnProperty(senderID)) {
|
| 29 |
+
allUserID.push(senderID)
|
| 30 |
+
await Users.createData(senderID)
|
| 31 |
+
logger.log(global.getText('handleCreateDatabase', 'newUser', senderID), 'DATABASE');
|
| 32 |
+
}
|
| 33 |
+
return;
|
| 34 |
+
} catch (err) {
|
| 35 |
+
return console.log(err);
|
| 36 |
+
}
|
| 37 |
+
};
|
| 38 |
+
}
|
includes/handle/handleEvent.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
module.exports = function ({api ,models, Users, Threads, Currencies, ...rest }) {
|
| 2 |
+
const logger = require("../../utils/log.js");
|
| 3 |
+
const moment = require("moment");
|
| 4 |
+
return function ({ event, ...rest2 }) {
|
| 5 |
+
const timeStart = Date.now()
|
| 6 |
+
const time = moment.tz("Asia/Manila").format("HH:MM:ss L");
|
| 7 |
+
const { userBanned, threadBanned } = global.data;
|
| 8 |
+
const { events } = global.client;
|
| 9 |
+
const { allowInbox, DeveloperMode } = global.config;
|
| 10 |
+
var { senderID, threadID } = event;
|
| 11 |
+
senderID = String(senderID);
|
| 12 |
+
threadID = String(threadID);
|
| 13 |
+
if (userBanned.has(senderID)|| threadBanned.has(threadID) || allowInbox == ![] && senderID == threadID) return;
|
| 14 |
+
for (const [key, value] of events.entries()) {
|
| 15 |
+
if (value.config.eventType.indexOf(event.logMessageType) !== -1) {
|
| 16 |
+
const eventRun = events.get(key);
|
| 17 |
+
try {
|
| 18 |
+
const Obj = {
|
| 19 |
+
...rest,
|
| 20 |
+
...rest2
|
| 21 |
+
};
|
| 22 |
+
Obj.api = api
|
| 23 |
+
Obj.event = event
|
| 24 |
+
Obj.models= models
|
| 25 |
+
Obj.Users= Users
|
| 26 |
+
Obj.Threads = Threads
|
| 27 |
+
Obj.Currencies = Currencies
|
| 28 |
+
eventRun.run(Obj);
|
| 29 |
+
if (DeveloperMode == !![])
|
| 30 |
+
logger.log(global.getText('handleEvent', 'executeEvent', time, eventRun.config.name, threadID, Date.now() - timeStart), 'Event');
|
| 31 |
+
} catch (error) {
|
| 32 |
+
logger.log(global.getText('handleEvent', 'eventError', eventRun.config.name, JSON.stringify(error)), "error");
|
| 33 |
+
}
|
| 34 |
+
}
|
| 35 |
+
}
|
| 36 |
+
return;
|
| 37 |
+
};
|
| 38 |
+
}
|
includes/handle/handleReaction.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
module.exports = function ({ api, models, Users, Threads, Currencies, ...rest }) {
|
| 2 |
+
return function ({ event, ...rest2 }) {
|
| 3 |
+
const { handleReaction, commands } = global.client;
|
| 4 |
+
const { messageID, threadID } = event;
|
| 5 |
+
if (handleReaction.length !== 0) {
|
| 6 |
+
const indexOfHandle = handleReaction.findIndex(e => e.messageID == messageID);
|
| 7 |
+
if (indexOfHandle < 0) return;
|
| 8 |
+
const indexOfMessage = handleReaction[indexOfHandle];
|
| 9 |
+
const handleNeedExec = commands.get(indexOfMessage.name);
|
| 10 |
+
|
| 11 |
+
if (!handleNeedExec) return api.sendMessage(global.getText('handleReaction', 'missingValue'), threadID, messageID);
|
| 12 |
+
try {
|
| 13 |
+
var getText2;
|
| 14 |
+
if (handleNeedExec.languages && typeof handleNeedExec.languages == 'object')
|
| 15 |
+
getText2 = (...value) => {
|
| 16 |
+
const react = handleNeedExec.languages || {};
|
| 17 |
+
if (!react.hasOwnProperty(global.config.language))
|
| 18 |
+
return api.sendMessage(global.getText('handleCommand', 'notFoundLanguage', handleNeedExec.config.name), threadID, messageID);
|
| 19 |
+
var lang = handleNeedExec.languages[global.config.language][value[0]] || '';
|
| 20 |
+
for (var i = value.length; i > 0x2 * -0xb7d + 0x2111 * 0x1 + -0xa17; i--) {
|
| 21 |
+
const expReg = RegExp('%' + i, 'g');
|
| 22 |
+
lang = lang.replace(expReg, value[i]);
|
| 23 |
+
}
|
| 24 |
+
return lang;
|
| 25 |
+
};
|
| 26 |
+
else getText2 = () => {};
|
| 27 |
+
const Obj = {
|
| 28 |
+
...rest,
|
| 29 |
+
...rest2
|
| 30 |
+
};
|
| 31 |
+
Obj.api= api
|
| 32 |
+
Obj.event = event
|
| 33 |
+
Obj.models = models
|
| 34 |
+
Obj.Users = Users
|
| 35 |
+
Obj.Threads = Threads
|
| 36 |
+
Obj.Currencies = Currencies
|
| 37 |
+
Obj.handleReaction = indexOfMessage
|
| 38 |
+
Obj.models= models
|
| 39 |
+
Obj.getText = getText2
|
| 40 |
+
handleNeedExec.handleReaction(Obj);
|
| 41 |
+
return;
|
| 42 |
+
} catch (error) {
|
| 43 |
+
return api.sendMessage(global.getText('handleReaction', 'executeError', error), threadID, messageID);
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
};
|
| 47 |
+
};
|
includes/handle/handleRefresh.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* @author D-Jukie
|
| 3 |
+
* @warn Do not edit code or edit credits
|
| 4 |
+
* @src Disme Project
|
| 5 |
+
* @bug fixed by @YanMaglinte
|
| 6 |
+
*/
|
| 7 |
+
module.exports = function ({ api, Threads }) {
|
| 8 |
+
const logger = require("../../utils/log.js");
|
| 9 |
+
return async function ({ event }) {
|
| 10 |
+
const { threadID, logMessageType, logMessageData } = event;
|
| 11 |
+
const { setData, getData, delData } = Threads;
|
| 12 |
+
try {
|
| 13 |
+
let dataThread = (await getData(threadID)).threadInfo;
|
| 14 |
+
switch (logMessageType) {
|
| 15 |
+
case "log:thread-admins": {
|
| 16 |
+
if (logMessageData.ADMIN_EVENT == "add_admin") {
|
| 17 |
+
dataThread.adminIDs.push({
|
| 18 |
+
id: logMessageData.TARGET_ID
|
| 19 |
+
})
|
| 20 |
+
} else if (logMessageData.ADMIN_EVENT == "remove_admin") {
|
| 21 |
+
dataThread.adminIDs = dataThread.adminIDs.filter(item => item.id != logMessageData.TARGET_ID);
|
| 22 |
+
}
|
| 23 |
+
logger.log('Refresh the list of admins in the group ' + threadID, 'UPDATE DATA')
|
| 24 |
+
await setData(threadID, { threadInfo: dataThread });
|
| 25 |
+
break;
|
| 26 |
+
}
|
| 27 |
+
case "log:thread-name": {
|
| 28 |
+
logger.log('Update name in group ' + threadID, 'UPDATE DATA')
|
| 29 |
+
dataThread.threadName = event.logMessageData.name
|
| 30 |
+
await setData(threadID, { threadInfo: dataThread });
|
| 31 |
+
break;
|
| 32 |
+
}
|
| 33 |
+
case "log:subscribe": {
|
| 34 |
+
if (event.logMessageData.addedParticipants.some(i => i.userFbId == api.getCurrentUserID())) return
|
| 35 |
+
for(let i of event.logMessageData.addedParticipants) {
|
| 36 |
+
dataThread.participantIDs.push(i.userFbId)
|
| 37 |
+
}
|
| 38 |
+
var data = await Threads.setData(event.threadID, {threadInfo: dataThread})
|
| 39 |
+
logger.log('Perform more group data ' + threadID, 'ADD DATA')
|
| 40 |
+
break;
|
| 41 |
+
}
|
| 42 |
+
case 'log:unsubscribe': {
|
| 43 |
+
if (logMessageData.leftParticipantFbId == api.getCurrentUserID()) {
|
| 44 |
+
logger.log('Perform group data deletion ' + threadID, 'DELETE DATA')
|
| 45 |
+
const index = global.data.allThreadID.findIndex(item => item == threadID);
|
| 46 |
+
global.data.allThreadID.splice(index, 1);
|
| 47 |
+
await delData(threadID);
|
| 48 |
+
return
|
| 49 |
+
} else {
|
| 50 |
+
const index = dataThread.participantIDs.findIndex(item => item == logMessageData.leftParticipantFbId);
|
| 51 |
+
dataThread.participantIDs.splice(index, 1);
|
| 52 |
+
if (dataThread.adminIDs.find(i => i.id == logMessageData.leftParticipantFbId)) {
|
| 53 |
+
dataThread.adminIDs = dataThread.adminIDs.filter(item => item.id != logMessageData.leftParticipantFbId);
|
| 54 |
+
}
|
| 55 |
+
logger.log('Perform user deletion ' + logMessageData.leftParticipantFbId, 'DELETE DATA')
|
| 56 |
+
await setData(threadID, { threadInfo: dataThread });
|
| 57 |
+
}
|
| 58 |
+
break;
|
| 59 |
+
}
|
| 60 |
+
}
|
| 61 |
+
} catch (e) {
|
| 62 |
+
console.log('There was an error updating data: ' + e)
|
| 63 |
+
}
|
| 64 |
+
return;
|
| 65 |
+
};
|
| 66 |
+
}
|
includes/handle/handleReply.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
module.exports = function ({ api, models, Users, Threads, Currencies, ...rest }) {
|
| 2 |
+
return function ({ event, ...rest2 }) {
|
| 3 |
+
if (!event.messageReply) return;
|
| 4 |
+
const { handleReply, commands } = global.client
|
| 5 |
+
const { messageID, threadID, messageReply } = event;
|
| 6 |
+
if (handleReply.length !== 0) {
|
| 7 |
+
const indexOfHandle = handleReply.findIndex(e => e.messageID == messageReply.messageID);
|
| 8 |
+
if (indexOfHandle < 0) return;
|
| 9 |
+
const indexOfMessage = handleReply[indexOfHandle];
|
| 10 |
+
const handleNeedExec = commands.get(indexOfMessage.name);
|
| 11 |
+
if (!handleNeedExec) return api.sendMessage(global.getText('handleReply', 'missingValue'), threadID, messageID);
|
| 12 |
+
try {
|
| 13 |
+
var getText2;
|
| 14 |
+
if (handleNeedExec.languages && typeof handleNeedExec.languages == 'object')
|
| 15 |
+
getText2 = (...value) => {
|
| 16 |
+
const reply = handleNeedExec.languages || {};
|
| 17 |
+
if (!reply.hasOwnProperty(global.config.language))
|
| 18 |
+
return api.sendMessage(global.getText('handleCommand', 'notFoundLanguage', handleNeedExec.config.name), threadID, messageID);
|
| 19 |
+
var lang = handleNeedExec.languages[global.config.language][value[0]] || '';
|
| 20 |
+
for (var i = value.length; i > -0x4 * 0x4db + 0x6d * 0x55 + -0x597 * 0x3; i--) {
|
| 21 |
+
const expReg = RegExp('%' + i, 'g');
|
| 22 |
+
lang = lang.replace(expReg, value[i]);
|
| 23 |
+
}
|
| 24 |
+
return lang;
|
| 25 |
+
};
|
| 26 |
+
else getText2 = () => {};
|
| 27 |
+
const Obj = {
|
| 28 |
+
...rest,
|
| 29 |
+
...rest2
|
| 30 |
+
};
|
| 31 |
+
Obj.api = api
|
| 32 |
+
Obj.event = event
|
| 33 |
+
Obj.models = models
|
| 34 |
+
Obj.Users = Users
|
| 35 |
+
Obj.Threads = Threads
|
| 36 |
+
Obj.Currencies = Currencies
|
| 37 |
+
Obj.handleReply = indexOfMessage
|
| 38 |
+
Obj.models = models
|
| 39 |
+
Obj.getText = getText2
|
| 40 |
+
handleNeedExec.handleReply(Obj);
|
| 41 |
+
return;
|
| 42 |
+
} catch (error) {
|
| 43 |
+
return api.sendMessage(global.getText('handleReply', 'executeError', error), threadID, messageID);
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
};
|
| 47 |
+
}
|