2021-10-24 22:41:46 +01:00
|
|
|
// ___ _ ___ _
|
|
|
|
|
// / __> _ _ ___ ___ ___ _ _ _| |_ | . > ___ _| |_
|
|
|
|
|
// \__ \| | || . \| . \/ . \| '_> | | | . \/ . \ | |
|
|
|
|
|
// <___/`___|| _/| _/\___/|_| |_| |___/\___/ |_|
|
|
|
|
|
// |_| |_|
|
2020-06-15 23:58:37 +01:00
|
|
|
//
|
2021-06-30 21:30:41 +01:00
|
|
|
// SupportBot created by Emerald Services
|
|
|
|
|
// Installed with MIT License
|
2021-02-02 17:15:24 +00:00
|
|
|
//
|
2021-06-30 21:30:41 +01:00
|
|
|
// Discord Support: https://emeraldsrv.dev/discord
|
2025-09-22 18:36:04 +01:00
|
|
|
// Community Resources: https://community.emeraldsrv.dev
|
2021-09-11 15:29:21 +01:00
|
|
|
|
2019-06-09 23:52:41 +01:00
|
|
|
const fs = require("fs");
|
2025-09-22 18:36:04 +01:00
|
|
|
const path = require("path");
|
2019-06-09 23:52:41 +01:00
|
|
|
|
2026-05-16 15:10:27 +01:00
|
|
|
const configStore = require("./Structures/ConfigStore.js");
|
2019-06-09 23:52:41 +01:00
|
|
|
|
2021-10-04 20:41:05 +01:00
|
|
|
const Client = require("./Structures/Client.js");
|
2024-06-12 12:54:31 +01:00
|
|
|
const client = new Client({
|
2026-05-16 15:10:27 +01:00
|
|
|
intents: ["Guilds", "GuildMembers", "GuildMessages", "MessageContent"],
|
2024-06-12 12:54:31 +01:00
|
|
|
});
|
2019-06-09 23:52:41 +01:00
|
|
|
|
2026-08-10 20:15:00 +01:00
|
|
|
const { isSetupComplete } = require("./Structures/DashboardSetup.js");
|
2026-04-21 13:37:39 +01:00
|
|
|
const APIServer = require("./API/server.js");
|
|
|
|
|
|
2026-05-16 15:10:27 +01:00
|
|
|
const api = new APIServer(client);
|
|
|
|
|
client.apiServer = api;
|
2024-06-12 12:54:31 +01:00
|
|
|
|
2026-08-10 20:15:00 +01:00
|
|
|
const port = api.config?.Port || 25575;
|
2026-05-16 15:10:27 +01:00
|
|
|
if (api.config?.Enabled) {
|
|
|
|
|
api.start(port);
|
2026-08-10 20:15:00 +01:00
|
|
|
if (!isSetupComplete()) {
|
|
|
|
|
console.log(`\n\x1b[33m\x1b[1m[Setup Required] Go to http://localhost:${port}/setup to set up your bot and dashboard.\x1b[0m\n`);
|
|
|
|
|
}
|
2026-05-16 15:10:27 +01:00
|
|
|
} else {
|
|
|
|
|
console.warn("[Dashboard] API disabled in Configs/api.yml");
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-10 20:15:00 +01:00
|
|
|
const token = configStore.supportbot?.General?.Token;
|
|
|
|
|
const isPlaceholderToken = !token || token.includes("BOT_TOKEN") || token.includes("CHANGE_ME") || token.length < 30;
|
2026-05-16 15:10:27 +01:00
|
|
|
|
2026-08-10 20:15:00 +01:00
|
|
|
if (isPlaceholderToken) {
|
|
|
|
|
console.warn(`\x1b[33m[SupportBot] Bot token is not configured yet. Complete setup at http://localhost:${port}/setup\x1b[0m`);
|
|
|
|
|
} else {
|
|
|
|
|
client.start(token);
|
|
|
|
|
}
|
2026-04-21 13:37:39 +01:00
|
|
|
|
2025-09-22 18:36:04 +01:00
|
|
|
// SupportBot - New Logging System
|
2024-06-12 12:54:31 +01:00
|
|
|
|
2025-09-22 18:36:04 +01:00
|
|
|
const logTypes = ["Output", "Warn", "Error"];
|
2024-06-12 12:54:31 +01:00
|
|
|
|
2025-09-22 18:36:04 +01:00
|
|
|
if (!fs.existsSync("./Logs")) {
|
|
|
|
|
fs.mkdirSync("./Logs");
|
|
|
|
|
}
|
|
|
|
|
logTypes.forEach((type) => {
|
|
|
|
|
const dir = `./Logs/${type}`;
|
|
|
|
|
if (!fs.existsSync(dir)) {
|
|
|
|
|
fs.mkdirSync(dir);
|
|
|
|
|
}
|
|
|
|
|
});
|
2024-06-12 12:54:31 +01:00
|
|
|
|
2025-09-22 18:36:04 +01:00
|
|
|
function logToFile(type, data) {
|
|
|
|
|
const date = new Date().toISOString().split("T")[0];
|
2025-09-25 13:09:00 +01:00
|
|
|
const file = path.join(`./Logs/${type}`, `${type}-${date}.log`);
|
2026-08-06 16:30:04 +01:00
|
|
|
const timestamp = new Date().toISOString();
|
|
|
|
|
fs.appendFileSync(file, `[${timestamp}] ${data}\n`);
|
|
|
|
|
|
|
|
|
|
if (global.apiServer) {
|
|
|
|
|
global.apiServer.broadcast("log", {
|
|
|
|
|
type,
|
|
|
|
|
timestamp,
|
|
|
|
|
message: String(data)
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-09-22 18:36:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const origLog = console.log;
|
|
|
|
|
console.log = (...args) => {
|
|
|
|
|
origLog(...args);
|
2025-09-25 13:09:00 +01:00
|
|
|
logToFile("Output", args.join(" "));
|
2025-09-22 18:36:04 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const origWarn = console.warn;
|
|
|
|
|
console.warn = (...args) => {
|
|
|
|
|
origWarn(...args);
|
2025-09-25 13:09:00 +01:00
|
|
|
logToFile("Warn", args.join(" "));
|
2025-09-22 18:36:04 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const origError = console.error;
|
|
|
|
|
console.error = (...args) => {
|
|
|
|
|
origError(...args);
|
2025-09-25 13:09:00 +01:00
|
|
|
logToFile("Error", args.join(" "));
|
2025-09-22 18:36:04 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
process.on("unhandledRejection", (reason) => {
|
|
|
|
|
console.error("Unhandled Rejection:", reason);
|
|
|
|
|
});
|
2024-06-12 12:54:31 +01:00
|
|
|
|
2025-09-22 18:36:04 +01:00
|
|
|
process.on("uncaughtException", (err) => {
|
|
|
|
|
console.error("Uncaught Exception:", err);
|
|
|
|
|
});
|