2021-10-04 20:41:05 +01:00
|
|
|
// SupportBot | Emerald Services
|
|
|
|
|
// Client Structure
|
|
|
|
|
|
|
|
|
|
const fs = require("fs");
|
|
|
|
|
|
|
|
|
|
const Discord = require("discord.js");
|
|
|
|
|
const intents = new Discord.Intents(32767);
|
|
|
|
|
|
2021-10-24 22:41:46 +01:00
|
|
|
const yaml = require("js-yaml");
|
2021-10-27 19:30:10 -05:00
|
|
|
const supportbot = yaml.load(
|
|
|
|
|
fs.readFileSync("./Configs/supportbot.yml", "utf8")
|
|
|
|
|
);
|
2021-10-04 20:41:05 +01:00
|
|
|
|
|
|
|
|
class Client extends Discord.Client {
|
2021-10-24 22:41:46 +01:00
|
|
|
constructor() {
|
|
|
|
|
super({ intents });
|
2021-10-04 20:41:05 +01:00
|
|
|
|
2021-10-24 22:41:46 +01:00
|
|
|
this.commands = new Discord.Collection();
|
|
|
|
|
}
|
2021-12-15 00:19:40 -06:00
|
|
|
async getChannel(channel, guild) {
|
|
|
|
|
return guild.channels.cache.find(
|
|
|
|
|
(c) =>
|
|
|
|
|
(c.type === "GUILD_TEXT" || c.type === "GUILD_NEWS") &&
|
|
|
|
|
(c.id === channel || c.name.toLowerCase() === channel.toLowerCase())
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
async getRole(role, guild) {
|
|
|
|
|
return guild.roles.cache.find(
|
|
|
|
|
(r) => r.id === role || r.name.toLowerCase() === role.toLowerCase()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
async getCategory(category, guild) {
|
|
|
|
|
return guild.channels.cache.find(
|
|
|
|
|
(c) =>
|
|
|
|
|
c.type === "GUILD_CATEGORY" &&
|
|
|
|
|
(c.id === category || c.name.toLowerCase() === category.toLowerCase())
|
|
|
|
|
);
|
|
|
|
|
}
|
2021-10-04 20:41:05 +01:00
|
|
|
|
2022-01-29 23:57:10 -06:00
|
|
|
async start(token) {
|
2022-06-18 11:19:12 +09:30
|
|
|
var tempCommandFiles = fs.readdirSync("./Commands").filter((file) => file.endsWith(".js"));
|
2022-06-21 01:38:22 +01:00
|
|
|
|
|
|
|
|
if (supportbot.Suggestions) {
|
2022-06-18 11:19:12 +09:30
|
|
|
tempCommandFiles = tempCommandFiles.filter(item => item !== "suggest.js");
|
|
|
|
|
}
|
2022-06-21 01:38:22 +01:00
|
|
|
|
2022-06-18 11:19:12 +09:30
|
|
|
const commandFiles = tempCommandFiles;
|
2021-10-04 20:41:05 +01:00
|
|
|
|
2021-10-25 00:13:27 +01:00
|
|
|
const addonFiles = fs
|
2022-01-30 00:07:04 -06:00
|
|
|
.readdirSync("./Addons")
|
|
|
|
|
.filter((file) => file.endsWith(".js"));
|
2021-10-25 00:13:27 +01:00
|
|
|
|
2021-12-18 18:57:45 -06:00
|
|
|
const addons = addonFiles.map((file) => {
|
|
|
|
|
let addon = require(`../Addons/${file}`);
|
|
|
|
|
addon.name = file.split(".")[0];
|
|
|
|
|
return addon;
|
|
|
|
|
});
|
2021-10-25 00:02:17 -05:00
|
|
|
|
2021-10-24 22:41:46 +01:00
|
|
|
const commands = commandFiles.map((file) => require(`../Commands/${file}`));
|
2021-10-04 20:41:05 +01:00
|
|
|
|
2021-12-18 18:57:45 -06:00
|
|
|
// Commands
|
2021-10-24 22:41:46 +01:00
|
|
|
console.log(`\u001b[34;1m`, "▬▬▬▬▬▬▬ Commands ▬▬▬▬▬▬▬");
|
2021-10-04 20:41:05 +01:00
|
|
|
|
2021-10-24 22:41:46 +01:00
|
|
|
commands.forEach((cmd) => {
|
|
|
|
|
console.log(`\u001b[31;1m`, `${cmd.name}`, `\u001b[32;1m`, "Loaded");
|
|
|
|
|
this.commands.set(cmd.name, cmd);
|
|
|
|
|
});
|
2021-10-21 19:28:23 +01:00
|
|
|
|
2021-12-18 18:57:45 -06:00
|
|
|
console.log(`\u001b[34;1m`, "▬▬▬▬▬▬▬ Commands ▬▬▬▬▬▬▬");
|
|
|
|
|
// Addons
|
|
|
|
|
console.log(" ");
|
|
|
|
|
console.log(`\u001b[34;1m`, "▬▬▬▬▬▬▬ Addons ▬▬▬▬▬▬▬");
|
|
|
|
|
|
2021-10-24 22:41:46 +01:00
|
|
|
addons.forEach((addon) => {
|
2021-10-25 00:02:17 -05:00
|
|
|
console.log(
|
2022-01-30 00:07:04 -06:00
|
|
|
`\u001b[33m`,
|
|
|
|
|
`[ADDON]`,
|
|
|
|
|
`\u001b[31;1m`,
|
|
|
|
|
`${addon.name}`,
|
|
|
|
|
`\u001b[32;1m`,
|
|
|
|
|
"Loaded"
|
2021-10-25 00:02:17 -05:00
|
|
|
);
|
2022-02-25 21:57:54 -06:00
|
|
|
addon.commands?.forEach((command) => {
|
2021-12-18 18:57:45 -06:00
|
|
|
this.commands.set(command.name, command);
|
|
|
|
|
});
|
2022-02-25 21:57:54 -06:00
|
|
|
addon.events?.forEach((event) => {
|
2021-12-18 18:57:45 -06:00
|
|
|
this.on(event.event, (...args) => event.run(this, ...args));
|
|
|
|
|
});
|
2021-10-24 22:41:46 +01:00
|
|
|
});
|
2021-10-21 19:28:23 +01:00
|
|
|
|
2021-12-18 18:57:45 -06:00
|
|
|
console.log(`\u001b[34;1m`, "▬▬▬▬▬▬▬ Addons ▬▬▬▬▬▬▬");
|
2021-10-21 19:28:23 +01:00
|
|
|
|
2021-10-24 22:41:46 +01:00
|
|
|
// Slash Commands
|
2021-10-21 19:28:23 +01:00
|
|
|
|
2021-12-18 18:57:45 -06:00
|
|
|
this.once("ready", async () => {
|
2022-02-17 19:57:37 -06:00
|
|
|
await this.guilds.cache.first()?.commands.set(this.commands);
|
2021-12-18 18:57:45 -06:00
|
|
|
console.log(
|
2022-01-30 00:07:04 -06:00
|
|
|
`\u001b[32;1m`,
|
|
|
|
|
`Slash Commands Registered for ${this.guilds.cache.first().name}`
|
2021-10-25 00:13:27 +01:00
|
|
|
);
|
2021-10-24 22:41:46 +01:00
|
|
|
});
|
2021-10-21 19:28:23 +01:00
|
|
|
|
2021-10-24 22:41:46 +01:00
|
|
|
console.log(" ");
|
|
|
|
|
console.log(`\u001b[34;1m`, "▬▬▬▬▬▬▬ Events ▬▬▬▬▬▬▬");
|
2021-10-21 19:28:23 +01:00
|
|
|
|
2021-10-24 22:41:46 +01:00
|
|
|
fs.readdirSync("./Events")
|
2022-01-30 00:07:04 -06:00
|
|
|
.filter((file) => file.endsWith(".js"))
|
|
|
|
|
.forEach((file) => {
|
|
|
|
|
const event = require(`../Events/${file}`);
|
|
|
|
|
console.log(`\u001b[31;1m`, `${event.event}`, `\u001b[32;1m`, "Loaded");
|
|
|
|
|
this.on(event.event, (...args) => event.run(this, ...args));
|
|
|
|
|
});
|
2021-10-21 19:28:23 +01:00
|
|
|
|
2021-10-24 22:41:46 +01:00
|
|
|
console.log(`\u001b[34;1m`, "▬▬▬▬▬▬▬ Events ▬▬▬▬▬▬▬");
|
2022-01-29 23:57:10 -06:00
|
|
|
if (process.argv[2] !== "test") {
|
|
|
|
|
await this.login(token);
|
2021-12-04 21:19:51 -06:00
|
|
|
} else {
|
|
|
|
|
console.log(
|
2022-01-30 00:07:04 -06:00
|
|
|
`\u001b[31;1m`,
|
|
|
|
|
"RUNNING IN TEST MODE, IF NOT INTENDED, PLEASE USE npm start"
|
2021-12-04 21:19:51 -06:00
|
|
|
);
|
|
|
|
|
}
|
2021-10-24 22:41:46 +01:00
|
|
|
}
|
2021-10-04 20:41:05 +01:00
|
|
|
}
|
|
|
|
|
|
2021-10-24 22:41:46 +01:00
|
|
|
module.exports = Client;
|