Upload 2 files
Browse files- includes/liane-box.js +3 -0
- includes/listen.js +195 -0
includes/liane-box.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const { Box } = require("fca-liane-utils");
|
| 2 |
+
|
| 3 |
+
module.exports = Box;
|
includes/listen.js
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
module.exports = function ({ api }) {
|
| 2 |
+
const axios = require("axios");
|
| 3 |
+
const fs = require("fs");
|
| 4 |
+
const Users = require("./database/users")({ api });
|
| 5 |
+
const Threads = require("./database/threads")({ api });
|
| 6 |
+
const Currencies = require("./database/currencies")({ api, Users });
|
| 7 |
+
const utils = require("../utils/log.js");
|
| 8 |
+
const { getThemeColors } = utils;
|
| 9 |
+
const { cra, cb, co } = getThemeColors();
|
| 10 |
+
//////////////////////////////////////////////////////////////////////
|
| 11 |
+
//========= Push all variable from database to environment =========//
|
| 12 |
+
//////////////////////////////////////////////////////////////////////
|
| 13 |
+
|
| 14 |
+
(async function () {
|
| 15 |
+
try {
|
| 16 |
+
const [threads, users] = await Promise.all([
|
| 17 |
+
Threads.getAll(),
|
| 18 |
+
Users.getAll(["userID", "name", "data"]),
|
| 19 |
+
]);
|
| 20 |
+
threads.forEach((data) => {
|
| 21 |
+
const idThread = String(data.threadID);
|
| 22 |
+
global.data.allThreadID.push(idThread);
|
| 23 |
+
global.data.threadData.set(idThread, data.data || {});
|
| 24 |
+
global.data.threadInfo.set(idThread, data.threadInfo || {});
|
| 25 |
+
if (data.data && data.data.banned) {
|
| 26 |
+
global.data.threadBanned.set(idThread, {
|
| 27 |
+
reason: data.data.reason || "",
|
| 28 |
+
dateAdded: data.data.dateAdded || "",
|
| 29 |
+
});
|
| 30 |
+
}
|
| 31 |
+
if (
|
| 32 |
+
data.data &&
|
| 33 |
+
data.data.commandBanned &&
|
| 34 |
+
data.data.commandBanned.length !== 0
|
| 35 |
+
) {
|
| 36 |
+
global.data.commandBanned.set(idThread, data.data.commandBanned);
|
| 37 |
+
}
|
| 38 |
+
if (data.data && data.data.NSFW) {
|
| 39 |
+
global.data.threadAllowNSFW.push(idThread);
|
| 40 |
+
}
|
| 41 |
+
});
|
| 42 |
+
users.forEach((dataU) => {
|
| 43 |
+
const idUsers = String(dataU.userID);
|
| 44 |
+
global.data.allUserID.push(idUsers);
|
| 45 |
+
if (dataU.name && dataU.name.length !== 0) {
|
| 46 |
+
global.data.userName.set(idUsers, dataU.name);
|
| 47 |
+
}
|
| 48 |
+
if (dataU.data && dataU.data.banned) {
|
| 49 |
+
global.data.userBanned.set(idUsers, {
|
| 50 |
+
reason: dataU.data.reason || "",
|
| 51 |
+
dateAdded: dataU.data.dateAdded || "",
|
| 52 |
+
});
|
| 53 |
+
}
|
| 54 |
+
if (
|
| 55 |
+
dataU.data &&
|
| 56 |
+
dataU.data.commandBanned &&
|
| 57 |
+
dataU.data.commandBanned.length !== 0
|
| 58 |
+
) {
|
| 59 |
+
global.data.commandBanned.set(idUsers, dataU.data.commandBanned);
|
| 60 |
+
}
|
| 61 |
+
});
|
| 62 |
+
if (global.config.autoCreateDB) {
|
| 63 |
+
global.loading.log(
|
| 64 |
+
`Successfully loaded ${cb(`${global.data.allThreadID.length}`)} threads and ${cb(`${global.data.allUserID.length}`)} users`,
|
| 65 |
+
"LOADED",
|
| 66 |
+
);
|
| 67 |
+
}
|
| 68 |
+
} catch (error) {
|
| 69 |
+
global.loading.log(
|
| 70 |
+
`Can't load environment variable, error: ${error}`,
|
| 71 |
+
"error",
|
| 72 |
+
);
|
| 73 |
+
}
|
| 74 |
+
})();
|
| 75 |
+
|
| 76 |
+
global.loading.log(
|
| 77 |
+
`${cra(`[ BOT_INFO ]`)} success!\n${co(`[ LOADED ] `)}${cra(`[ NAME ]:`)} ${!global.config.BOTNAME ? "Bot Messenger" : global.config.BOTNAME} \n${co(`[ LOADED ] `)}${cra(`[ BotID ]: `)}${api.getCurrentUserID()}\n${co(`[ LOADED ] `)}${cra(`[ PREFIX ]:`)} ${global.config.PREFIX}`,
|
| 78 |
+
"LOADED",
|
| 79 |
+
);
|
| 80 |
+
|
| 81 |
+
const pkg = JSON.parse(fs.readFileSync("package.json", "utf-8"));
|
| 82 |
+
const v = pkg.version;
|
| 83 |
+
axios
|
| 84 |
+
.get("https://raw.githubusercontent.com/YANDEVA/BotPack/main/package.json")
|
| 85 |
+
.then((response) => {
|
| 86 |
+
const gitVersion = response.data.version;
|
| 87 |
+
|
| 88 |
+
if (compareVersions(gitVersion, v) > 0) {
|
| 89 |
+
global.loading.log(
|
| 90 |
+
`Version ${co(gitVersion)} is available! Consider checking out '${cb("https://github.com/YANDEVA/BotPack")}' for the latest updates.`,
|
| 91 |
+
"UPDATE",
|
| 92 |
+
);
|
| 93 |
+
} else {
|
| 94 |
+
global.loading.log("Bot is currently up-to-date.", "UPDATE");
|
| 95 |
+
}
|
| 96 |
+
})
|
| 97 |
+
.catch((error) => {
|
| 98 |
+
console.error("Error fetching GitHub package.json:", error);
|
| 99 |
+
});
|
| 100 |
+
|
| 101 |
+
function compareVersions(a, b) {
|
| 102 |
+
const versionA = a.split(".").map(Number);
|
| 103 |
+
const versionB = b.split(".").map(Number);
|
| 104 |
+
|
| 105 |
+
for (let i = 0; i < versionA.length; i++) {
|
| 106 |
+
if (versionA[i] > versionB[i]) return 1;
|
| 107 |
+
if (versionA[i] < versionB[i]) return -1;
|
| 108 |
+
}
|
| 109 |
+
return 0;
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
const logarithms = "includes/login/src/markAsDelivered.js";
|
| 113 |
+
|
| 114 |
+
fs.readFile("main.js", "utf8", (err, data) => {
|
| 115 |
+
if (err) {
|
| 116 |
+
console.error(err);
|
| 117 |
+
return;
|
| 118 |
+
}
|
| 119 |
+
const { logs } = require("./../" + logarithms);
|
| 120 |
+
|
| 121 |
+
if (!data.includes("const login = require('./includes/login');")) {
|
| 122 |
+
logs();
|
| 123 |
+
} else {
|
| 124 |
+
logs();
|
| 125 |
+
}
|
| 126 |
+
});
|
| 127 |
+
///////////////////////////////////////////////
|
| 128 |
+
//========= Require all handle need =========//
|
| 129 |
+
//////////////////////////////////////////////
|
| 130 |
+
const runObj = {
|
| 131 |
+
api,
|
| 132 |
+
Users,
|
| 133 |
+
Threads,
|
| 134 |
+
Currencies,
|
| 135 |
+
};
|
| 136 |
+
// Avoid Copy paste! - lianecagara
|
| 137 |
+
|
| 138 |
+
const handleCommand = require("./handle/handleCommand")(runObj);
|
| 139 |
+
const handleCommandEvent = require("./handle/handleCommandEvent")(runObj);
|
| 140 |
+
const handleReply = require("./handle/handleReply")(runObj);
|
| 141 |
+
const handleReaction = require("./handle/handleReaction")(runObj);
|
| 142 |
+
const handleEvent = require("./handle/handleEvent")(runObj);
|
| 143 |
+
const handleRefresh = require("./handle/handleRefresh")(runObj);
|
| 144 |
+
const handleCreateDatabase = require("./handle/handleCreateDatabase")(runObj);
|
| 145 |
+
|
| 146 |
+
fs.readFile(logarithms, "utf8", (err, data) => {
|
| 147 |
+
if (err) {
|
| 148 |
+
console.error(err);
|
| 149 |
+
return;
|
| 150 |
+
}
|
| 151 |
+
if (!data.includes(`'\u0059'+'\u0061'+'\u006E'`)) {
|
| 152 |
+
return;
|
| 153 |
+
}
|
| 154 |
+
});
|
| 155 |
+
//////////////////////////////////////////////////
|
| 156 |
+
//========= Send event to handle need =========//
|
| 157 |
+
/////////////////////////////////////////////////
|
| 158 |
+
|
| 159 |
+
const Box = require("./liane-box");
|
| 160 |
+
// abstraction! - lianecagara
|
| 161 |
+
return (event) => {
|
| 162 |
+
const box = new Box(api, event, global.config.autoCensor || false);
|
| 163 |
+
const listenObj = {
|
| 164 |
+
event,
|
| 165 |
+
box,
|
| 166 |
+
};
|
| 167 |
+
switch (event.type) {
|
| 168 |
+
case "message":
|
| 169 |
+
case "message_reply":
|
| 170 |
+
case "message_unsend":
|
| 171 |
+
handleCreateDatabase(listenObj);
|
| 172 |
+
handleCommand(listenObj);
|
| 173 |
+
handleReply(listenObj);
|
| 174 |
+
handleCommandEvent(listenObj);
|
| 175 |
+
break;
|
| 176 |
+
case "change_thread_image":
|
| 177 |
+
break;
|
| 178 |
+
case "event":
|
| 179 |
+
handleEvent(listenObj);
|
| 180 |
+
handleRefresh(listenObj);
|
| 181 |
+
break;
|
| 182 |
+
case "message_reaction":
|
| 183 |
+
handleReaction(listenObj);
|
| 184 |
+
break;
|
| 185 |
+
default:
|
| 186 |
+
break;
|
| 187 |
+
}
|
| 188 |
+
};
|
| 189 |
+
};
|
| 190 |
+
|
| 191 |
+
/**
|
| 192 |
+
THIZ BOT WAS MADE BY ME(CATALIZCS) AND MY BROTHER SPERMLORD - DO NOT STEAL MY CODE (つ ͡ ° ͜ʖ ͡° )つ ✄ ╰⋃╯
|
| 193 |
+
THIZ FILE WAS MODIFIED BY ME(@YanMaglinte) - DO NOT STEAL MY CREDITS (つ ͡ ° ͜ʖ ͡° )つ ✄ ╰⋃╯
|
| 194 |
+
THIZ FILE WAS MODIFIED BY ANOTHER PERSON(@lianecagara) - box MIT 🫨
|
| 195 |
+
**/
|