2020-12-03 16:30:33 +00:00
|
|
|
if (process.platform === "win32") console.log("\x1b[1m\x1b[31m\x1b[40m" + `WIN32 IS NOT OFFICIALLY SUPPORTED!
|
|
|
|
Although there's a (very) slim chance of it working, multiple aspects of the bot are built with UNIX-like systems in mind and could break on Win32-based systems. If you want to run the bot on Windows, using Windows Subsystem for Linux is highly recommended.
|
|
|
|
The bot will continue to run past this message, but keep in mind that it could break at any time. Continue running at your own risk; alternatively, stop the bot using Ctrl+C and install WSL.` + "\x1b[0m");
|
|
|
|
|
2019-11-13 00:09:06 +00:00
|
|
|
// load config from .env file
|
|
|
|
require("dotenv").config();
|
|
|
|
|
2019-09-13 20:02:41 +00:00
|
|
|
// turn fs.readdir into a promise
|
2020-02-19 22:46:50 +00:00
|
|
|
const readdir = require("util").promisify(require("fs").readdir);
|
2019-09-13 20:02:41 +00:00
|
|
|
// fancy loggings
|
|
|
|
const logger = require("./utils/logger.js");
|
|
|
|
// start the client
|
|
|
|
const client = require("./utils/client.js");
|
|
|
|
// initialize command loader
|
|
|
|
const handler = require("./utils/handler.js");
|
2020-06-27 21:34:31 +00:00
|
|
|
const sound = require("./utils/soundplayer.js");
|
2021-01-18 20:11:28 +00:00
|
|
|
const image = require("./utils/image.js");
|
2019-09-13 20:02:41 +00:00
|
|
|
|
2020-02-19 22:46:50 +00:00
|
|
|
// registers stuff and connects the bot
|
2019-09-13 20:02:41 +00:00
|
|
|
async function init() {
|
2020-06-27 21:34:31 +00:00
|
|
|
logger.log("info", "Starting esmBot...");
|
2019-12-02 20:47:22 +00:00
|
|
|
// register commands and their info
|
2019-09-13 20:02:41 +00:00
|
|
|
const commands = await readdir("./commands/");
|
2020-06-27 21:34:31 +00:00
|
|
|
const soundStatus = await sound.checkStatus();
|
2019-09-13 20:02:41 +00:00
|
|
|
logger.log("info", `Attempting to load ${commands.length} commands...`);
|
2019-11-30 02:00:14 +00:00
|
|
|
for (const commandFile of commands) {
|
2019-09-13 20:02:41 +00:00
|
|
|
logger.log("info", `Loading command ${commandFile}...`);
|
|
|
|
try {
|
2020-06-27 21:34:31 +00:00
|
|
|
await handler.load(commandFile, soundStatus);
|
2019-09-13 20:02:41 +00:00
|
|
|
} catch (e) {
|
|
|
|
logger.error(`Failed to register command ${commandFile.split(".")[0]}: ${e}`);
|
|
|
|
}
|
2019-11-30 02:00:14 +00:00
|
|
|
}
|
2019-09-13 20:02:41 +00:00
|
|
|
|
|
|
|
// register events
|
|
|
|
const events = await readdir("./events/");
|
|
|
|
logger.log("info", `Attempting to load ${events.length} events...`);
|
2019-11-30 02:00:14 +00:00
|
|
|
for (const file of events) {
|
2019-09-13 20:02:41 +00:00
|
|
|
logger.log("info", `Loading event ${file}...`);
|
|
|
|
const eventName = file.split(".")[0];
|
|
|
|
const event = require(`./events/${file}`);
|
|
|
|
client.on(eventName, event);
|
2019-11-30 02:00:14 +00:00
|
|
|
}
|
2019-09-13 20:02:41 +00:00
|
|
|
|
2021-01-18 20:11:28 +00:00
|
|
|
// connect to image api if enabled
|
|
|
|
if (process.env.API === "true") {
|
|
|
|
for (const server of image.servers) {
|
|
|
|
try {
|
|
|
|
await image.connect(server);
|
|
|
|
} catch (e) {
|
|
|
|
logger.error(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-13 20:02:41 +00:00
|
|
|
// login
|
|
|
|
client.connect();
|
|
|
|
|
|
|
|
// post to DBL
|
2021-03-18 14:29:03 +00:00
|
|
|
if (process.env.NODE_ENV === "production" && process.env.DBL !== "") {
|
2019-12-20 14:25:29 +00:00
|
|
|
require("./utils/dbl.js");
|
|
|
|
}
|
2020-07-22 01:29:32 +00:00
|
|
|
|
|
|
|
// handle ctrl+c and pm2 stop
|
|
|
|
process.on("SIGINT", () => {
|
|
|
|
logger.log("info", "SIGINT detected, shutting down...");
|
|
|
|
client.editStatus("dnd", {
|
|
|
|
name: "Restarting/shutting down..."
|
|
|
|
});
|
|
|
|
for (const command of commands) {
|
|
|
|
handler.unload(command);
|
|
|
|
}
|
|
|
|
client.disconnect();
|
2020-12-19 00:57:41 +00:00
|
|
|
require("./utils/database.js").stop();
|
|
|
|
process.exit(0);
|
2020-07-22 01:29:32 +00:00
|
|
|
});
|
2019-09-13 20:02:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// launch the bot
|
2020-07-22 01:29:32 +00:00
|
|
|
init();
|