2019-09-13 20:02:41 +00:00
|
|
|
// check if using node 10 or higher
|
|
|
|
if (process.version.slice(1).split(".")[0] < 10) throw new Error("Node 10.0.0 or higher is required. Update Node on your system.");
|
|
|
|
|
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
|
|
|
|
const { promisify } = require("util");
|
|
|
|
const fs = require("fs");
|
|
|
|
const readdir = promisify(fs.readdir);
|
|
|
|
// 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");
|
|
|
|
|
|
|
|
// registers stuff and logs in the bot
|
|
|
|
async function init() {
|
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/");
|
|
|
|
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 {
|
2019-11-30 02:00:14 +00:00
|
|
|
await handler.load(commandFile);
|
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
|
|
|
|
|
|
|
// login
|
|
|
|
client.connect();
|
|
|
|
|
|
|
|
// post to DBL
|
2019-12-20 14:25:29 +00:00
|
|
|
if (process.env.NODE_ENV === "production") {
|
|
|
|
require("./utils/dbl.js");
|
|
|
|
}
|
2019-09-13 20:02:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// launch the bot
|
|
|
|
init();
|