diff --git a/src/handlers/commands.ts b/src/handlers/commands.ts index 8b75999..1df02fe 100644 --- a/src/handlers/commands.ts +++ b/src/handlers/commands.ts @@ -6,7 +6,7 @@ import { ICommand } from "../interfaces/Command"; export default async (client: Client) => { client.commands = new Collection(); - fs.readdir("./src/plugins", async (error, plugins) => { + fs.readdir("plugins", async (error, plugins) => { if (error) { return logger.error(`Error reading plugins: ${error}`); } diff --git a/src/helpers/getCommandMetadata/index.ts b/src/helpers/getCommandMetadata/index.ts index 71940d2..647eb75 100644 --- a/src/helpers/getCommandMetadata/index.ts +++ b/src/helpers/getCommandMetadata/index.ts @@ -9,6 +9,6 @@ export default async ( const subcommandGroup = interaction.options.getSubcommandGroup(false); return subcommandGroup - ? currentCommand.modules[subcommandGroup].modules[subcommand].metadata - : currentCommand.modules[subcommand].metadata; + ? currentCommand.moduleData[subcommandGroup].moduleData[subcommand].metadata + : currentCommand.moduleData[subcommand].metadata; }; diff --git a/src/interfaces/Command.ts b/src/interfaces/Command.ts index 34585d9..f8a895a 100644 --- a/src/interfaces/Command.ts +++ b/src/interfaces/Command.ts @@ -1,7 +1,7 @@ import { SlashCommandBuilder } from "@discordjs/builders"; export interface ICommand { - modules: any; builder: SlashCommandBuilder; + moduleData: any; execute: Promise; } diff --git a/src/managers/event/index.ts b/src/managers/event/index.ts index be51927..8a3a506 100644 --- a/src/managers/event/index.ts +++ b/src/managers/event/index.ts @@ -3,7 +3,7 @@ import { Client } from "discord.js"; import listDir from "../../helpers/listDir"; export const register = async (client: Client) => { - const eventNames = await listDir("src/events"); + const eventNames = await listDir("events"); if (!eventNames) return; for await (const eventName of eventNames) { diff --git a/src/plugins/config/index.ts b/src/plugins/config/index.ts index 0b82732..4110d5c 100644 --- a/src/plugins/config/index.ts +++ b/src/plugins/config/index.ts @@ -8,57 +8,36 @@ import modules from "./modules"; // Handlers import logger from "../../logger"; +export const builder = new SlashCommandBuilder() + .setName("config") + .setDescription("Manage guild configurations.") + + .addSubcommand(modules.pterodactyl.builder) + .addSubcommand(modules.credits.builder) + .addSubcommand(modules.points.builder) + .addSubcommand(modules.welcome.builder) + .addSubcommand(modules.audits.builder) + .addSubcommand(modules.shop.builder) + .addSubcommand(modules.embeds.builder); + +export const moduleData = modules; + // Function -export default { - modules, - - builder: new SlashCommandBuilder() - .setName("config") - .setDescription("Manage guild configurations.") - - .addSubcommand(modules.pterodactyl.builder) - .addSubcommand(modules.credits.builder) - .addSubcommand(modules.points.builder) - .addSubcommand(modules.welcome.builder) - .addSubcommand(modules.audits.builder) - .addSubcommand(modules.shop.builder) - .addSubcommand(modules.embeds.builder), - - async execute(interaction: CommandInteraction) { - // Destructure member - const { options } = interaction; - - switch (options?.getSubcommand()) { - case "pterodactyl": - logger?.silly(`Subcommand is pterodactyl`); - - return modules.pterodactyl.execute(interaction); - case "credits": - logger?.silly(`Subcommand is credits`); - - return modules.credits.execute(interaction); - case "points": - logger?.silly(`Subcommand is points`); - - return modules.points.execute(interaction); - case "welcome": - logger?.silly(`Subcommand is welcome`); - - return modules.welcome.execute(interaction); - case "audits": - logger?.silly(`Subcommand is audits`); - - return modules.audits.execute(interaction); - case "shop": - logger?.silly(`Subcommand is shop`); - - return modules.shop.execute(interaction); - case "embeds": - logger?.silly(`Subcommand is shop`); - - return modules.embeds.execute(interaction); - default: - logger?.silly(`Subcommand is not found`); - } - }, +export const execute = async (interaction: CommandInteraction) => { + switch (interaction.options?.getSubcommand()) { + case "pterodactyl": + return modules.pterodactyl.execute(interaction); + case "credits": + return modules.credits.execute(interaction); + case "points": + return modules.points.execute(interaction); + case "welcome": + return modules.welcome.execute(interaction); + case "audits": + return modules.audits.execute(interaction); + case "shop": + return modules.shop.execute(interaction); + case "embeds": + return modules.embeds.execute(interaction); + } }; diff --git a/src/plugins/counters/index.ts b/src/plugins/counters/index.ts index 57ec908..df23d0b 100644 --- a/src/plugins/counters/index.ts +++ b/src/plugins/counters/index.ts @@ -4,23 +4,16 @@ import logger from "../../logger"; import modules from "../../plugins/counters/modules"; -export default { - modules, +export const builder = new SlashCommandBuilder() + .setName("counters") + .setDescription("View guild counters") - builder: new SlashCommandBuilder() - .setName("counters") - .setDescription("View guild counters") + .addSubcommand(modules.view.builder); - .addSubcommand(modules.view.builder), +export const moduleData = modules; - async execute(interaction: CommandInteraction) { - const { options } = interaction; - - if (options.getSubcommand() === "view") { - logger.silly(`Executing view subcommand`); - return modules.view.execute(interaction); - } - - logger.silly(`Unknown subcommand ${options.getSubcommand()}`); - }, +export const execute = async (interaction: CommandInteraction) => { + if (interaction.options.getSubcommand() === "view") { + await modules.view.execute(interaction); + } }; diff --git a/src/plugins/credits/index.ts b/src/plugins/credits/index.ts index 1e1860f..02c03a5 100644 --- a/src/plugins/credits/index.ts +++ b/src/plugins/credits/index.ts @@ -2,38 +2,36 @@ import { SlashCommandBuilder } from "@discordjs/builders"; import { CommandInteraction } from "discord.js"; import logger from "../../logger"; -import modules from "../../plugins/credits/modules"; +import modules from "./modules"; -export default { - modules, +export const builder = new SlashCommandBuilder() + .setName("credits") + .setDescription("Manage your credits.") - builder: new SlashCommandBuilder() - .setName("credits") - .setDescription("Manage your credits.") + .addSubcommand(modules.balance.builder) + .addSubcommand(modules.gift.builder) + .addSubcommand(modules.top.builder) + .addSubcommand(modules.work.builder); - .addSubcommand(modules.balance.builder) - .addSubcommand(modules.gift.builder) - .addSubcommand(modules.top.builder) - .addSubcommand(modules.work.builder), +export const moduleData = modules; - async execute(interaction: CommandInteraction) { - const { options } = interaction; +export const execute = async (interaction: CommandInteraction) => { + const { options } = interaction; - switch (options.getSubcommand()) { - case "balance": - await modules.balance.execute(interaction); - break; - case "gift": - await modules.gift.execute(interaction); - break; - case "top": - await modules.top.execute(interaction); - break; - case "work": - await modules.work.execute(interaction); - break; - default: - logger.silly(`Unknown subcommand ${options.getSubcommand()}`); - } - }, + switch (options.getSubcommand()) { + case "balance": + await modules.balance.execute(interaction); + break; + case "gift": + await modules.gift.execute(interaction); + break; + case "top": + await modules.top.execute(interaction); + break; + case "work": + await modules.work.execute(interaction); + break; + default: + logger.silly(`Unknown subcommand ${options.getSubcommand()}`); + } }; diff --git a/src/plugins/fun/index.ts b/src/plugins/fun/index.ts index 687c036..758814c 100644 --- a/src/plugins/fun/index.ts +++ b/src/plugins/fun/index.ts @@ -4,22 +4,20 @@ import logger from "../../logger"; import modules from "../../plugins/fun/modules"; -export default { - modules, +export const builder = new SlashCommandBuilder() + .setName("fun") + .setDescription("Fun commands.") - builder: new SlashCommandBuilder() - .setName("fun") - .setDescription("Fun commands.") + .addSubcommand(modules.meme.builder); - .addSubcommand(modules.meme.builder), +export const moduleData = modules; - async execute(interaction: CommandInteraction) { - const { options } = interaction; +export const execute = async (interaction: CommandInteraction) => { + const { options } = interaction; - if (options.getSubcommand() === "meme") { - await modules.meme.execute(interaction); - } else { - logger.silly(`Unknown subcommand ${options.getSubcommand()}`); - } - }, + if (options.getSubcommand() === "meme") { + await modules.meme.execute(interaction); + } else { + logger.silly(`Unknown subcommand ${options.getSubcommand()}`); + } }; diff --git a/src/plugins/manage/index.ts b/src/plugins/manage/index.ts index 7f51c88..a54f2e2 100644 --- a/src/plugins/manage/index.ts +++ b/src/plugins/manage/index.ts @@ -6,32 +6,24 @@ import { CommandInteraction } from "discord.js"; import modules from "../../plugins/manage/modules"; import logger from "../../logger"; +export const moduleData = modules; + // Function -export default { - modules, +export const builder = new SlashCommandBuilder() + .setName("manage") + .setDescription("Manage the bot.") + .addSubcommandGroup(modules.counters.builder) + .addSubcommandGroup(modules.credits.builder); - builder: new SlashCommandBuilder() - .setName("manage") - .setDescription("Manage the bot.") - .addSubcommandGroup(modules.counters.builder) - .addSubcommandGroup(modules.credits.builder), +export const execute = async (interaction: CommandInteraction) => { + // Destructure + const { options } = interaction; - async execute(interaction: CommandInteraction) { - // Destructure - const { options } = interaction; + if (options?.getSubcommandGroup() === "credits") { + return modules.credits.execute(interaction); + } - if (options?.getSubcommandGroup() === "credits") { - logger?.silly(`Subcommand group is credits`); - - return modules.credits.execute(interaction); - } - - if (options?.getSubcommandGroup() === "counters") { - logger?.silly(`Subcommand group is counters`); - - return modules.counters.execute(interaction); - } - - logger?.silly(`Subcommand group is not credits or counters`); - }, + if (options?.getSubcommandGroup() === "counters") { + return modules.counters.execute(interaction); + } }; diff --git a/src/plugins/manage/modules/counters/index.ts b/src/plugins/manage/modules/counters/index.ts index d5c351c..36d6cd9 100644 --- a/src/plugins/manage/modules/counters/index.ts +++ b/src/plugins/manage/modules/counters/index.ts @@ -8,32 +8,30 @@ import logger from "../../../../logger"; import modules from "./modules"; // Function -export default { - modules, +export const moduleData = modules; - builder: (group: SlashCommandSubcommandGroupBuilder) => { - return group - .setName("counters") - .setDescription("Manage guild counters.") - .addSubcommand(modules.add.builder) - .addSubcommand(modules.remove.builder); - }, - - execute: async (interaction: CommandInteraction) => { - const { options } = interaction; - - if (options?.getSubcommand() === "add") { - logger?.silly(`Executing create subcommand`); - - return modules.add.execute(interaction); - } - - if (options?.getSubcommand() === "remove") { - logger?.silly(`Executing delete subcommand`); - - return modules.remove.execute(interaction); - } - - logger?.silly(`Unknown subcommand ${options?.getSubcommand()}`); - }, +export const builder = (group: SlashCommandSubcommandGroupBuilder) => { + return group + .setName("counters") + .setDescription("Manage guild counters.") + .addSubcommand(modules.add.builder) + .addSubcommand(modules.remove.builder); +}; + +export const execute = async (interaction: CommandInteraction) => { + const { options } = interaction; + + if (options?.getSubcommand() === "add") { + logger?.silly(`Executing create subcommand`); + + return modules.add.execute(interaction); + } + + if (options?.getSubcommand() === "remove") { + logger?.silly(`Executing delete subcommand`); + + return modules.remove.execute(interaction); + } + + logger?.silly(`Unknown subcommand ${options?.getSubcommand()}`); }; diff --git a/src/plugins/manage/modules/credits/index.ts b/src/plugins/manage/modules/credits/index.ts index 11e4563..cd6819b 100644 --- a/src/plugins/manage/modules/credits/index.ts +++ b/src/plugins/manage/modules/credits/index.ts @@ -4,40 +4,27 @@ import logger from "../../../../logger"; import modules from "./modules"; -export default { - modules, +export const moduleData = modules; - builder: (group: SlashCommandSubcommandGroupBuilder) => { - return group - .setName("credits") - .setDescription("Manage the credits of a user.") - .addSubcommand(modules.give.builder) - .addSubcommand(modules.set.builder) - .addSubcommand(modules.take.builder) - .addSubcommand(modules.transfer.builder); - }, - execute: async (interaction: CommandInteraction) => { - const { options } = interaction; - - switch (options.getSubcommand()) { - case "give": - logger.silly(`Executing give subcommand`); - - return modules.give.execute(interaction); - case "set": - logger.silly(`Executing set subcommand`); - - return modules.set.execute(interaction); - case "take": - logger.silly(`Executing take subcommand`); - - return modules.take.execute(interaction); - case "transfer": - logger.silly(`Executing transfer subcommand`); - - return modules.transfer.execute(interaction); - default: - logger.silly(`Unknown subcommand ${options.getSubcommand()}`); - } - }, +export const builder = (group: SlashCommandSubcommandGroupBuilder) => { + return group + .setName("credits") + .setDescription("Manage the credits of a user.") + .addSubcommand(modules.give.builder) + .addSubcommand(modules.set.builder) + .addSubcommand(modules.take.builder) + .addSubcommand(modules.transfer.builder); +}; + +export const execute = async (interaction: CommandInteraction) => { + switch (interaction.options.getSubcommand()) { + case "give": + return modules.give.execute(interaction); + case "set": + return modules.set.execute(interaction); + case "take": + return modules.take.execute(interaction); + case "transfer": + return modules.transfer.execute(interaction); + } }; diff --git a/src/plugins/manage/modules/index.ts b/src/plugins/manage/modules/index.ts index e9b808b..c55982f 100644 --- a/src/plugins/manage/modules/index.ts +++ b/src/plugins/manage/modules/index.ts @@ -1,4 +1,4 @@ -import counters from "./counters"; -import credits from "./credits"; +import * as counters from "./counters"; +import * as credits from "./credits"; export default { counters, credits }; diff --git a/src/plugins/profile/index.ts b/src/plugins/profile/index.ts index bb3c5b3..808c9e7 100644 --- a/src/plugins/profile/index.ts +++ b/src/plugins/profile/index.ts @@ -8,23 +8,22 @@ import modules from "../../plugins/profile/modules"; // Handlers import logger from "../../logger"; +export const moduleData = modules; + // Function -export default { - modules, +export const builder = new SlashCommandBuilder() + .setName("profile") + .setDescription("Check a profile.") + .addSubcommand(modules.view.builder); - builder: new SlashCommandBuilder() - .setName("profile") - .setDescription("Check a profile.") - .addSubcommand(modules.view.builder), - async execute(interaction: CommandInteraction) { - const { options } = interaction; +export const execute = async (interaction: CommandInteraction) => { + const { options } = interaction; - if (options?.getSubcommand() === "view") { - logger?.silly(`Executing view subcommand`); + if (options?.getSubcommand() === "view") { + logger?.silly(`Executing view subcommand`); - return modules.view.execute(interaction); - } + return modules.view.execute(interaction); + } - logger?.silly(`No subcommand found`); - }, + logger?.silly(`No subcommand found`); }; diff --git a/src/plugins/reputation/index.ts b/src/plugins/reputation/index.ts index a027d7e..b0812d4 100644 --- a/src/plugins/reputation/index.ts +++ b/src/plugins/reputation/index.ts @@ -8,22 +8,22 @@ import modules from "./modules"; // Handlers import logger from "../../logger"; +export const moduleData = modules; + // Function -export default { - modules, - builder: new SlashCommandBuilder() - .setName("reputation") - .setDescription("Manage reputation.") - .addSubcommand(modules.give.builder), - async execute(interaction: CommandInteraction) { - const { options } = interaction; +export const builder = new SlashCommandBuilder() + .setName("reputation") + .setDescription("Manage reputation.") + .addSubcommand(modules.give.builder); - if (options?.getSubcommand() === "give") { - logger?.silly(`Executing give subcommand`); +export const execute = async (interaction: CommandInteraction) => { + const { options } = interaction; - await modules.give.execute(interaction); - } + if (options?.getSubcommand() === "give") { + logger?.silly(`Executing give subcommand`); - logger?.silly(`No subcommand found`); - }, + await modules.give.execute(interaction); + } + + logger?.silly(`No subcommand found`); }; diff --git a/src/plugins/shop/index.ts b/src/plugins/shop/index.ts index 330306e..2ef6f65 100644 --- a/src/plugins/shop/index.ts +++ b/src/plugins/shop/index.ts @@ -8,30 +8,29 @@ import modules from "./modules"; // Handlers import logger from "../../logger"; +export const moduleData = modules; + // Function -export default { - modules, +export const builder = new SlashCommandBuilder() + .setName("shop") + .setDescription("Shop for credits and custom roles.") + .addSubcommand(modules.pterodactyl.builder) + .addSubcommandGroup(modules.roles.builder); - builder: new SlashCommandBuilder() - .setName("shop") - .setDescription("Shop for credits and custom roles.") - .addSubcommand(modules.pterodactyl.builder) - .addSubcommandGroup(modules.roles.builder), - async execute(interaction: CommandInteraction) { - const { options } = interaction; +export const execute = async (interaction: CommandInteraction) => { + const { options } = interaction; - if (options?.getSubcommand() === "pterodactyl") { - logger.silly(`Executing pterodactyl subcommand`); + if (options?.getSubcommand() === "pterodactyl") { + logger.silly(`Executing pterodactyl subcommand`); - return modules.pterodactyl.execute(interaction); - } + return modules.pterodactyl.execute(interaction); + } - if (options?.getSubcommandGroup() === "roles") { - logger?.silly(`Subcommand group is roles`); + if (options?.getSubcommandGroup() === "roles") { + logger?.silly(`Subcommand group is roles`); - return modules.roles.execute(interaction); - } + return modules.roles.execute(interaction); + } - logger?.silly(`No subcommand found.`); - }, + logger?.silly(`No subcommand found.`); }; diff --git a/src/plugins/shop/modules/index.ts b/src/plugins/shop/modules/index.ts index e39fb66..d191ec6 100644 --- a/src/plugins/shop/modules/index.ts +++ b/src/plugins/shop/modules/index.ts @@ -1,4 +1,4 @@ import pterodactyl from "./pterodactyl"; -import roles from "./roles"; +import * as roles from "./roles"; export default { pterodactyl, roles }; diff --git a/src/plugins/shop/modules/roles/index.ts b/src/plugins/shop/modules/roles/index.ts index a4ffb2a..bdec977 100644 --- a/src/plugins/shop/modules/roles/index.ts +++ b/src/plugins/shop/modules/roles/index.ts @@ -12,59 +12,54 @@ import modules from "./modules"; import guildSchema from "../../../../database/schemas/guild"; +export const moduleData = modules; + // Function -export default { - modules, - - builder: (group: SlashCommandSubcommandGroupBuilder) => { - return group - .setName("roles") - .setDescription("Shop for custom roles.") - .addSubcommand(modules.buy.builder) - .addSubcommand(modules.cancel.builder); - }, - execute: async (interaction: CommandInteraction) => { - if (interaction.guild == null) return; - const { errorColor, footerText, footerIcon } = await getEmbedConfig( - interaction.guild - ); - const { options, guild } = interaction; - - const guildDB = await guildSchema?.findOne({ - guildId: guild?.id, - }); - - if (guildDB === null) return; - - if (!guildDB.shop.roles.status) { - logger.silly(`Shop roles disabled.`); - - return interaction?.editReply({ - embeds: [ - { - title: ":dollar: Shop - Roles", - description: "This server has disabled shop roles.", - color: errorColor, - timestamp: new Date(), - footer: { - iconURL: footerIcon, - text: footerText, - }, - }, - ], - }); - } - - if (options?.getSubcommand() === "buy") { - logger.silly(`Executing buy subcommand`); - - await modules.buy.execute(interaction); - } - - if (options?.getSubcommand() === "cancel") { - logger.silly(`Executing cancel subcommand`); - - await modules.cancel.execute(interaction); - } - }, +export const builder = (group: SlashCommandSubcommandGroupBuilder) => { + return group + .setName("roles") + .setDescription("Shop for custom roles.") + .addSubcommand(modules.buy.builder) + .addSubcommand(modules.cancel.builder); +}; + +export const execute = async (interaction: CommandInteraction) => { + if (interaction.guild == null) return; + const { errorColor, footerText, footerIcon } = await getEmbedConfig( + interaction.guild + ); + const { options, guild } = interaction; + + const guildDB = await guildSchema?.findOne({ + guildId: guild?.id, + }); + + if (guildDB === null) return; + + if (!guildDB.shop.roles.status) { + logger.silly(`Shop roles disabled.`); + + return interaction?.editReply({ + embeds: [ + { + title: ":dollar: Shop - Roles", + description: "This server has disabled shop roles.", + color: errorColor, + timestamp: new Date(), + footer: { + iconURL: footerIcon, + text: footerText, + }, + }, + ], + }); + } + + if (options?.getSubcommand() === "buy") { + await modules.buy.execute(interaction); + } + + if (options?.getSubcommand() === "cancel") { + await modules.cancel.execute(interaction); + } }; diff --git a/src/plugins/utility/index.ts b/src/plugins/utility/index.ts index b831189..4849a3b 100644 --- a/src/plugins/utility/index.ts +++ b/src/plugins/utility/index.ts @@ -8,33 +8,31 @@ import modules from "../../plugins/utility/modules"; // Handlers import logger from "../../logger"; +export const moduleData = modules; + // Function -export default { - modules, +export const builder = new SlashCommandBuilder() + .setName("utility") + .setDescription("Common utility.") - builder: new SlashCommandBuilder() - .setName("utility") - .setDescription("Common utility.") + .addSubcommand(modules.lookup.builder) + .addSubcommand(modules.about.builder) + .addSubcommand(modules.stats.builder) + .addSubcommand(modules.avatar.builder); - .addSubcommand(modules.lookup.builder) - .addSubcommand(modules.about.builder) - .addSubcommand(modules.stats.builder) - .addSubcommand(modules.avatar.builder), +export const execute = async (interaction: CommandInteraction) => { + const { options } = interaction; - async execute(interaction: CommandInteraction) { - const { options } = interaction; - - switch (options.getSubcommand()) { - case "lookup": - return modules.lookup.execute(interaction); - case "about": - return modules.about.execute(interaction); - case "stats": - return modules.stats.execute(interaction); - case "avatar": - return modules.avatar.execute(interaction); - default: - logger.error(`Unknown subcommand ${options.getSubcommand()}`); - } - }, + switch (options.getSubcommand()) { + case "lookup": + return modules.lookup.execute(interaction); + case "about": + return modules.about.execute(interaction); + case "stats": + return modules.stats.execute(interaction); + case "avatar": + return modules.avatar.execute(interaction); + default: + logger.error(`Unknown subcommand ${options.getSubcommand()}`); + } };