Files
SupportBot/Structures/Client.js
T

199 lines
6.5 KiB
JavaScript
Raw Normal View History

2021-10-04 20:41:05 +01:00
const fs = require("fs");
const Discord = require("discord.js");
2022-07-22 13:19:05 +01:00
const { GatewayIntentBits, Partials } = require('discord.js');
2021-10-24 22:41:46 +01:00
const yaml = require("js-yaml");
2024-07-03 13:46:57 +01:00
const { Command, Event } = require('./Addon.js'); // Adjust the path as needed
2022-08-11 19:19:29 +01:00
2024-06-13 17:36:44 +01:00
const supportbot = yaml.load(fs.readFileSync("./Configs/supportbot.yml", "utf8"));
const cmdconfig = yaml.load(fs.readFileSync("./Configs/commands.yml", "utf8"));
2022-08-11 19:19:29 +01:00
2021-10-04 20:41:05 +01:00
class Client extends Discord.Client {
2021-10-24 22:41:46 +01:00
constructor() {
2024-06-12 12:54:31 +01:00
super({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
2024-11-09 00:37:51 +00:00
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent
2024-06-12 12:54:31 +01:00
],
2024-11-09 00:37:51 +00:00
partials: [Partials.Message, Partials.Channel]
2024-06-12 12:54:31 +01:00
});
2021-10-04 20:41:05 +01:00
2021-10-24 22:41:46 +01:00
this.commands = new Discord.Collection();
}
2024-06-13 17:36:44 +01:00
async getChannel(channel, guild) {
2024-06-13 17:36:44 +01:00
if (!channel) return null; // Add check for undefined channel
return guild.channels.cache.find(
(c) =>
2022-08-11 19:19:29 +01:00
(c.type === Discord.ChannelType.GuildText || c.type === Discord.ChannelType.GuildNews) &&
2024-06-13 17:36:44 +01:00
(c.id === channel || (c.name && c.name.toLowerCase() === channel.toLowerCase()))
);
}
2024-06-13 17:36:44 +01:00
async getRole(role, guild) {
2024-06-13 17:36:44 +01:00
if (!role) return null; // Add check for undefined role
return guild.roles.cache.find(
2024-06-13 17:36:44 +01:00
(r) => r.id === role || (r.name && r.name.toLowerCase() === role.toLowerCase())
);
}
2024-06-13 17:36:44 +01:00
async getCategory(category, guild) {
2024-06-13 17:36:44 +01:00
if (!category) return null; // Add check for undefined category
return guild.channels.cache.find(
(c) =>
2022-08-11 19:19:29 +01:00
c.type === Discord.ChannelType.GuildCategory &&
2024-06-13 17:36:44 +01:00
(c.id === category || (c.name && c.name.toLowerCase() === category.toLowerCase()))
);
}
2021-10-04 20:41:05 +01:00
2022-01-29 23:57:10 -06:00
async start(token) {
2024-06-13 17:36:44 +01:00
let tempCommandFiles = fs.readdirSync("./Commands").filter((file) => file.endsWith(".js"));
2022-06-21 01:38:22 +01:00
2022-08-11 19:19:29 +01:00
if (cmdconfig.Suggestion.Enabled === false) {
tempCommandFiles = tempCommandFiles.filter(item => item !== "suggest.js");
}
2022-08-11 19:19:29 +01:00
if (cmdconfig.Help.Enabled === false) {
tempCommandFiles = tempCommandFiles.filter(item => item !== "help.js");
}
if (cmdconfig.Info.Enabled === false) {
tempCommandFiles = tempCommandFiles.filter(item => item !== "info.js");
}
if (cmdconfig.OpenTicket.Enabled === false) {
tempCommandFiles = tempCommandFiles.filter(item => item !== "ticket.js");
}
if (cmdconfig.CloseTicket.Enabled === false) {
tempCommandFiles = tempCommandFiles.filter(item => item !== "close.js");
}
if (cmdconfig.Embed.Enabled === false) {
tempCommandFiles = tempCommandFiles.filter(item => item !== "embed.js");
}
if (cmdconfig.Translate.Enabled === false) {
tempCommandFiles = tempCommandFiles.filter(item => item !== "translate.js");
}
if (cmdconfig.UserInfo.Enabled === false) {
tempCommandFiles = tempCommandFiles.filter(item => item !== "userinfo.js");
}
if (cmdconfig.Ping.Enabled === false) {
tempCommandFiles = tempCommandFiles.filter(item => item !== "Ping.js");
}
2024-07-09 22:49:49 +01:00
if (cmdconfig.AddUser.Enabled === false) {
tempCommandFiles = tempCommandFiles.filter(item => item !== "addUser.js");
2024-06-12 12:54:31 +01:00
}
2024-07-09 22:49:49 +01:00
if (cmdconfig.RemoveUser.Enabled === false) {
tempCommandFiles = tempCommandFiles.filter(item => item !== "removeUser.js");
}
if (cmdconfig.ForceAddUser.Enabled === false) {
tempCommandFiles = tempCommandFiles.filter(item => item !== "forceaddUser.js");
}
if (cmdconfig.Profile.Enabled === false) {
2024-10-10 19:14:45 +01:00
tempCommandFiles = tempCommandFiles.filter(item => item !== "profile.js");
}
if (cmdconfig.Settings.Enabled === false) {
tempCommandFiles = tempCommandFiles.filter(item => item !== "settings.js");
2024-07-09 22:49:49 +01:00
}
2024-11-09 00:37:51 +00:00
if (cmdconfig.Mod.Enabled === false) {
tempCommandFiles = tempCommandFiles.filter(item => item !== "mod.js");
}
const commandFiles = tempCommandFiles;
2021-10-24 22:41:46 +01:00
const commands = commandFiles.map((file) => require(`../Commands/${file}`));
2021-10-04 20:41:05 +01:00
2024-07-03 13:46:57 +01:00
// Load main commands
2024-07-30 17:45:35 +01:00
console.log(`\u001b[33m`, "――――――――――――――――――――――――――――――――――――――――――――");
2021-10-04 20:41:05 +01:00
2021-10-24 22:41:46 +01:00
commands.forEach((cmd) => {
2022-07-22 13:19:05 +01:00
console.log(`\u001b[32m`, `[CMD]`, `\u001b[37;1m`, `${cmd.name}`, `\u001b[32;1m`, "Loaded");
2021-10-24 22:41:46 +01:00
this.commands.set(cmd.name, cmd);
});
2021-10-21 19:28:23 +01:00
2024-07-03 13:46:57 +01:00
// Load addon commands and events
2024-07-30 17:45:35 +01:00
console.log(`\u001b[33m`, "▬▬▬▬▬▬▬ Commands ▬▬▬▬▬▬▬");
2021-12-18 18:57:45 -06:00
2022-08-12 01:35:36 +01:00
if (supportbot.General.Addons.Enabled) {
2024-06-13 17:36:44 +01:00
const addonFiles = fs.readdirSync("./Addons").filter((file) => file.endsWith(".js"));
2022-08-12 01:35:36 +01:00
const addons = addonFiles.map((file) => {
2024-07-03 13:46:57 +01:00
const addon = require(`../Addons/${file}`);
2022-08-12 01:35:36 +01:00
addon.name = file.split(".")[0];
return addon;
});
// Addons
console.log(" ");
2024-07-30 17:45:35 +01:00
console.log(`\u001b[33m`, "▬▬▬▬▬▬▬ Addons ▬▬▬▬▬▬▬");
2022-08-12 01:35:36 +01:00
addons.forEach((addon) => {
console.log(
`\u001b[32m`,
`[ADDON]`,
`\u001b[37;1m`,
`${addon.name}`,
`\u001b[32;1m`,
"Loaded"
);
2024-07-03 13:46:57 +01:00
if (addon instanceof Command) {
this.commands.set(addon.name, addon);
}
if (addon.events && Array.isArray(addon.events)) {
addon.events.forEach((event) => {
if (event instanceof Event) {
this.on(event.event, (...args) => event.run(this, ...args));
}
});
}
2021-12-18 18:57:45 -06:00
});
2021-10-21 19:28:23 +01:00
2024-07-30 17:45:35 +01:00
console.log(`\u001b[33m`, "▬▬▬▬▬▬▬ Addons ▬▬▬▬▬▬▬");
2024-06-13 17:36:44 +01:00
}
2022-08-12 01:35:36 +01:00
2024-07-03 13:46:57 +01:00
// Register 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-07-22 13:19:05 +01:00
"\u001b[32m",
`[SUCCESS]`,
`\u001b[37;1m`,
2022-01-30 00:07:04 -06:00
`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(" ");
2024-07-30 17:45:35 +01:00
console.log(`\u001b[33m`, "▬▬▬▬▬▬▬ Events ▬▬▬▬▬▬▬");
2021-10-21 19:28:23 +01:00
2024-06-13 17:36:44 +01:00
fs.readdirSync("./Events").filter((file) => file.endsWith(".js")).forEach((file) => {
const event = require(`../Events/${file}`);
console.log(`\u001b[32m`, `[EVENT]`, `\u001b[37;1m`, `${event.event}`, `\u001b[32;1m`, "Loaded");
this.on(event.event, (...args) => event.run(this, ...args));
});
2021-10-21 19:28:23 +01:00
2024-07-30 17:45:35 +01:00
console.log(`\u001b[33m`, "▬▬▬▬▬▬▬ 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
}
2025-08-07 13:54:35 +01:00
module.exports = Client;