New addon handler

This commit is contained in:
Noah committed 2021-12-18 18:57:45 -06:00
1 parent 4e554b8bee
commit e507176d39
4 files changed
+74 -91

No files matched your search

+29 -17
View File
@@ -11,23 +11,35 @@ const supportbot = yaml.load(
const cmdconfig = yaml.load(fs.readFileSync("./Configs/commands.yml", "utf8"));
// Your Addon Config file! Saved in /Addons/Configs/YourAddonConfig.yml
// const exampleaddon = yaml.load(fs.readFileSync('./Addons/Configs/YourAddonConfig.yml', 'utf8'));
// const config = yaml.load(fs.readFileSync('./Addons/Configs/YourAddonConfig.yml', 'utf8'));
const Command = require("../Structures/Command.js");
const { Command, Event } = require("../Structures/Addon");
module.exports = new Command({
name: "hello",
description: "hello",
slashCommandOptions: [],
permission: "SEND_MESSAGES",
module.exports.commands = [
/*
// EXAMPLE COMMAND
new Command({
name: "hello",
description: "hello",
options: [],
permissions: ["SEND_MESSAGES"],
async run(interaction) {
const Embed = new Discord.MessageEmbed()
.setDescription("Hello World!")
.setColor(supportbot.InfoColour);
async run(interaction) {
const Embed = new Discord.MessageEmbed()
.setDescription("Hello World!")
.setColor(supportbot.InfoColour);
interaction.reply({
embeds: [Embed],
});
},
});
interaction.reply({
embeds: [Embed],
});
},
}),
*/
];
module.exports.events = [
/*
// EXAMPLE EVENT
new Event("ready", async (client) => {
console.log("Bot started!");
}),
*/
];
+21
View File
@@ -0,0 +1,21 @@
// SupportBot | Emerald Services
// Addon Structure
class Command {
constructor(options) {
this.name = options.name;
this.description = options.description;
this.permissions = options.permissions;
this.options = options.options || [];
this.run = options.run;
this.defaultPermission = true;
}
}
class Event {
constructor(event, run) {
this.event = event;
this.run = run;
}
}
module.exports = { Command, Event };
-25
View File
@@ -1,25 +0,0 @@
// SupportBot | Emerald Services
// Addon Structure
const fs = require("fs");
const Discord = require("discord.js");
const yaml = require("js-yaml");
const supportbot = yaml.load(
fs.readFileSync("./Configs/supportbot.yml", "utf8")
);
function RunFunction(interaction) {}
class Addon {
constructor(options) {
this.name = options.name;
this.description = options.description;
this.permission = options.permission;
this.slashCommandOptions = options.slashCommandOptions || [];
this.run = options.run;
}
}
module.exports = Addon;
+24 -49
View File
@@ -4,8 +4,6 @@
const fs = require("fs");
const Discord = require("discord.js");
const Command = require("./Command.js");
const Event = require("./Event.js");
const intents = new Discord.Intents(32767);
const yaml = require("js-yaml");
@@ -48,10 +46,15 @@ class Client extends Discord.Client {
.readdirSync("./Addons")
.filter((file) => file.endsWith(".js"));
const addons = addonFiles.map((file) => require(`../Addons/${file}`));
const addons = addonFiles.map((file) => {
let addon = require(`../Addons/${file}`);
addon.name = file.split(".")[0];
return addon;
});
const commands = commandFiles.map((file) => require(`../Commands/${file}`));
// Commands
console.log(`\u001b[34;1m`, "▬▬▬▬▬▬▬ Commands ▬▬▬▬▬▬▬");
commands.forEach((cmd) => {
@@ -59,6 +62,11 @@ class Client extends Discord.Client {
this.commands.set(cmd.name, cmd);
});
console.log(`\u001b[34;1m`, "▬▬▬▬▬▬▬ Commands ▬▬▬▬▬▬▬");
// Addons
console.log(" ");
console.log(`\u001b[34;1m`, "▬▬▬▬▬▬▬ Addons ▬▬▬▬▬▬▬");
addons.forEach((addon) => {
console.log(
`\u001b[33m`,
@@ -68,55 +76,23 @@ class Client extends Discord.Client {
`\u001b[32;1m`,
"Loaded"
);
this.commands.set(addon.name, addon);
addon.commands.forEach((command) => {
this.commands.set(command.name, command);
});
addon.events.forEach((event) => {
this.on(event.event, (...args) => event.run(this, ...args));
});
});
console.log(`\u001b[34;1m`, "▬▬▬▬▬▬▬ Commands ▬▬▬▬▬▬▬");
console.log(`\u001b[34;1m`, "▬▬▬▬▬▬▬ Addons ▬▬▬▬▬▬▬");
// Slash Commands
const slashCommands = commands.map((cmd) => ({
name: cmd.name.toLowerCase(),
description: cmd.description,
permissions: [],
options: cmd.slashCommandOptions,
defaultPermission: true,
}));
const slashCommands1 = addons.map((addon) => ({
name: addon.name.toLowerCase(),
description: addon.description,
permissions: [],
options: addon.slashCommandOptions,
defaultPermission: true,
}));
this.removeAllListeners();
this.on("ready", async () => {
const allCommands = slashCommands.concat(slashCommands1);
await this.application?.commands.set(allCommands, supportbot.Guild);
console.log(" ");
console.log(`\u001b[34;1m`, "▬▬▬▬▬▬▬ Slash Commands ▬▬▬▬▬▬▬"),
console.log(" ");
slashCommands.forEach((cmd) =>
console.log(
`\u001b[31;1m`,
`${cmd.name}`,
`\u001b[32;1m`,
`| Slash Command Registered`
)
);
slashCommands1.forEach((addon) =>
console.log(
`\u001b[33m`,
`[ADDON]`,
`\u001b[31;1m`,
`${addon.name}`,
`\u001b[32;1m`,
`| Slash Command Registered`
)
this.once("ready", async () => {
await this.application?.commands.set(this.commands, supportbot.Guild);
console.log(
`\u001b[32;1m`,
`Slash Commands Registered for ${this.guilds.cache.first().name}`
);
});
@@ -128,8 +104,7 @@ class Client extends Discord.Client {
.forEach((file) => {
const event = require(`../Events/${file}`);
console.log(`\u001b[31;1m`, `${event.event}`, `\u001b[32;1m`, "Loaded");
this.on(event.event, event.run.bind(null, this));
this.on(event.event, (...args) => event.run(this, ...args));
});
console.log(`\u001b[34;1m`, "▬▬▬▬▬▬▬ Events ▬▬▬▬▬▬▬");