Files
SupportBot/index.js
T

92 lines
3.6 KiB
JavaScript
Raw Normal View History

2020-06-15 23:58:37 +01:00
// _________ __ __________ __
// / _____/__ ________ ______ ____________/ |\______ \ _____/ |_
// \_____ \| | \____ \\____ \ / _ \_ __ \ __\ | _// _ \ __\
// / \ | / |_> > |_> > <_> ) | \/| | | | ( <_> ) |
// /_______ /____/| __/| __/ \____/|__| |__| |______ /\____/|__|
// \/ |__| |__| \/
//
2021-05-14 15:46:08 +01:00
// SupportBot version 6.4
2020-06-15 23:58:37 +01:00
// Created by Emerald Services
// Installed with MIT License
2021-02-02 17:15:24 +00:00
//
// Support Server: discord.gg/jspKFcE
2019-06-09 23:52:41 +01:00
const Discord = require("discord.js");
const fs = require("fs");
const bot = new Discord.Client();
bot.commands = new Discord.Collection();
2020-01-25 13:48:02 +00:00
const yaml = require('js-yaml');
2020-01-25 13:55:33 +00:00
const supportbot = yaml.load(fs.readFileSync('./supportbot-config.yml', 'utf8'));
2020-01-25 13:48:02 +00:00
2020-06-15 23:58:37 +01:00
const { promisify } = require("util");
const readdir = promisify(require("fs").readdir);
2019-06-09 23:52:41 +01:00
2020-06-15 23:58:37 +01:00
String.prototype.toProperCase = function () {
return this.replace(
/([^\W_]+[^\s-]*) */g,
(txt) => txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase()
);
};
2019-06-09 23:52:41 +01:00
2020-06-15 23:58:37 +01:00
const init = async () => {
const evtFiles = await readdir("./events/");
evtFiles.forEach((file, i) => {
const eventName = file.split(".")[0];
const event = require(`./events/${file}`);
console.info(`\u001b[37m`, `[${supportbot.Bot_Name}]:`, `\u001b[31m`, `#${i + 1} Event Loaded: ${eventName.toProperCase()} `);
bot.on(eventName, event.bind(null, bot));
delete require.cache[require.resolve(`./events/${file}`)];
2019-06-09 23:52:41 +01:00
});
2020-04-16 16:43:16 +01:00
2020-06-15 23:58:37 +01:00
console.info(`\u001b[37m`, `[${supportbot.Bot_Name}]:`, `\u001b[32m`, `Successfully loaded ${evtFiles.length} events.`);
console.info(`\u001b[37m`, "-----------------------------------------------------------------------------");
};
2020-04-16 16:43:16 +01:00
2020-06-15 23:58:37 +01:00
init();
2020-04-16 16:43:16 +01:00
2020-06-15 23:58:37 +01:00
fs.readdir("./commands/", (err, files) => {
if (err) console.info(err, "error");
let jsfiles = files.filter((f) => f.split(".").pop() === "js");
2019-06-09 23:52:41 +01:00
2020-06-15 23:58:37 +01:00
if (jsfiles.length <= 0) {
console.log(`[${supportbot.Bot_Name}]: No commands found. Try to Re-download the resource`);
return;
}
2019-06-18 16:13:38 +01:00
2020-06-15 23:58:37 +01:00
jsfiles.forEach((f, i) => {
let props = require(`./commands/${f}`);
console.info(`\u001b[37m`, `[${supportbot.Bot_Name}]:`, `\u001b[31m`, `#${i + 1} Command Loaded: ${props.name.toProperCase()}`);
bot.commands.set(props.name, props);
});
2019-06-09 23:52:41 +01:00
2020-06-15 23:58:37 +01:00
console.info(`\u001b[37m`, `[${supportbot.Bot_Name}]:`, `\u001b[32m`, `Loaded ${jsfiles.length} commands!`);
console.info(`\u001b[37m`, "-----------------------------------------------------------------------------");
2019-06-09 23:52:41 +01:00
});
2020-06-15 23:58:37 +01:00
fs.readdir("./addons/", (err, files) => {
if (err) console.info(err, "error");
let jsfiles = files.filter((f) => f.split(".").pop() === "js");
2019-06-09 23:52:41 +01:00
2020-06-15 23:58:37 +01:00
if (jsfiles.length <= 0) {
console.log(`[${supportbot.Bot_Name}]: No addons found. You can download addons from https://emeraldservices.xyz`);
return;
}
jsfiles.forEach((f, i) => {
2020-07-15 18:42:07 +01:00
let props = require(`./addons/${f}`);
2020-06-15 23:58:37 +01:00
console.info(`\u001b[37m`, `[${supportbot.Bot_Name}]:`, `\u001b[31m`, `#${i + 1} Command Loaded: ${props.name.toProperCase()}`);
bot.commands.set(props.name, props);
});
2019-06-09 23:52:41 +01:00
2020-06-15 23:58:37 +01:00
console.info(`\u001b[37m`, `[${supportbot.Bot_Name}]:`, `\u001b[32m`, `Loaded ${jsfiles.length} commands!`);
console.info(`\u001b[37m`, "-----------------------------------------------------------------------------");
2019-06-09 23:52:41 +01:00
});
2021-05-14 15:46:08 +01:00
bot.login(supportbot.Token);