diff --git a/src/commands/shop/index.ts b/src/commands/shop/index.ts index 1da2442..bf3c20d 100644 --- a/src/commands/shop/index.ts +++ b/src/commands/shop/index.ts @@ -3,18 +3,18 @@ import { SlashCommandBuilder } from "@discordjs/builders"; import { ChatInputCommandInteraction } from "discord.js"; // Modules -import modules from "./modules"; - -// Handlers - -export const moduleData = modules; +import moduleCpgg from "./modules/cpgg"; +import moduleRoles from "./modules/roles"; // Function export const builder = new SlashCommandBuilder() .setName("shop") .setDescription("Shop for credits and custom roles.") - .addSubcommand(modules.cpgg.builder) - .addSubcommandGroup(modules.roles.builder); + .setDMPermission(false) + + // Modules + .addSubcommand(moduleCpgg.builder) + .addSubcommandGroup(moduleRoles.builder); // Execute the command export const execute = async (interaction: ChatInputCommandInteraction) => { @@ -22,7 +22,7 @@ export const execute = async (interaction: ChatInputCommandInteraction) => { switch (options.getSubcommand()) { case "cpgg": { - await modules.cpgg.execute(interaction); + await moduleCpgg.execute(interaction); break; } default: { @@ -32,7 +32,7 @@ export const execute = async (interaction: ChatInputCommandInteraction) => { switch (options.getSubcommandGroup()) { case "roles": { - await modules.roles.execute(interaction); + await moduleRoles.execute(interaction); break; } default: { diff --git a/src/commands/shop/modules/cpgg/index.ts b/src/commands/shop/modules/cpgg/index.ts index f7df0a4..1e50907 100644 --- a/src/commands/shop/modules/cpgg/index.ts +++ b/src/commands/shop/modules/cpgg/index.ts @@ -10,13 +10,12 @@ import { } from "discord.js"; import { v4 as uuidv4 } from "uuid"; import prisma from "../../../../handlers/database"; +import deferReply from "../../../../handlers/deferReply"; import encryption from "../../../../helpers/encryption"; import getEmbedData from "../../../../helpers/getEmbedData"; import logger from "../../../../middlewares/logger"; export default { - metadata: { guildOnly: true, ephemeral: true }, - builder: (command: SlashCommandSubcommandBuilder) => { return command .setName("cpgg") @@ -29,6 +28,8 @@ export default { ); }, execute: async (interaction: ChatInputCommandInteraction) => { + await deferReply(interaction, true); + const { errorColor, successColor, footerText, footerIcon } = await getEmbedData(interaction.guild); const { options, guild, user, client } = interaction; diff --git a/src/commands/shop/modules/index.ts b/src/commands/shop/modules/index.ts deleted file mode 100644 index c3df89d..0000000 --- a/src/commands/shop/modules/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import cpgg from "./cpgg"; -import * as roles from "./roles"; - -export default { cpgg, roles }; diff --git a/src/commands/shop/modules/roles/index.ts b/src/commands/shop/modules/roles/index.ts index ae87e29..0064d14 100644 --- a/src/commands/shop/modules/roles/index.ts +++ b/src/commands/shop/modules/roles/index.ts @@ -5,39 +5,42 @@ import { ChatInputCommandInteraction } from "discord.js"; // Handlers // Modules -import modules from "./modules"; +import moduleBuy from "./modules/buy"; +import moduleCancel from "./modules/cancel"; import guildSchema from "../../../../models/guild"; -export const moduleData = modules; +export default { + builder: (group: SlashCommandSubcommandGroupBuilder) => { + return ( + group + .setName("roles") + .setDescription("Shop for custom roles.") -// Function -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: ChatInputCommandInteraction) => { - if (!interaction.guild) return; - const { options, guild } = interaction; - - const guildDB = await guildSchema?.findOne({ - guildId: guild?.id, - }); - - if (guildDB === null) return; - - if (!guildDB.shop.roles.status) - throw new Error("This server has disabled shop roles."); - - if (options?.getSubcommand() === "buy") { - await modules.buy.execute(interaction); - } - - if (options?.getSubcommand() === "cancel") { - await modules.cancel.execute(interaction); - } + // Modules + .addSubcommand(moduleBuy.builder) + .addSubcommand(moduleCancel.builder) + ); + }, + execute: async (interaction: ChatInputCommandInteraction) => { + if (!interaction.guild) return; + const { options, guild } = interaction; + + const guildDB = await guildSchema?.findOne({ + guildId: guild?.id, + }); + + if (guildDB === null) return; + + if (!guildDB.shop.roles.status) + throw new Error("This server has disabled shop roles."); + + if (options?.getSubcommand() === "buy") { + await moduleBuy.execute(interaction); + } + + if (options?.getSubcommand() === "cancel") { + await moduleCancel.execute(interaction); + } + }, }; diff --git a/src/commands/shop/modules/roles/modules/buy/index.ts b/src/commands/shop/modules/roles/modules/buy/index.ts index f776e2c..e1ca0b2 100644 --- a/src/commands/shop/modules/roles/modules/buy/index.ts +++ b/src/commands/shop/modules/roles/modules/buy/index.ts @@ -2,14 +2,13 @@ // Helpers import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import { ChatInputCommandInteraction } from "discord.js"; +import deferReply from "../../../../../../handlers/deferReply"; // Configurations // import fetchUser from "../../../../../../helpers/userData"; // Models // Function export default { - metadata: { guildOnly: true, ephemeral: true }, - builder: (command: SlashCommandSubcommandBuilder) => { return command .setName("buy") @@ -28,6 +27,8 @@ export default { ); }, execute: async (interaction: ChatInputCommandInteraction) => { + await deferReply(interaction, true); + // const { successColor, footerText, footerIcon } = await getEmbedConfig( // interaction.guild // ); diff --git a/src/commands/shop/modules/roles/modules/cancel/index.ts b/src/commands/shop/modules/roles/modules/cancel/index.ts index 4d0cfc9..4f842f9 100644 --- a/src/commands/shop/modules/roles/modules/cancel/index.ts +++ b/src/commands/shop/modules/roles/modules/cancel/index.ts @@ -5,11 +5,10 @@ import { ChatInputCommandInteraction } from "discord.js"; // Configurations // import fetchUser from "../../../../../../helpers/userData"; // Models +import deferReply from "../../../../../../handlers/deferReply"; // Function export default { - metadata: { guildOnly: true, ephemeral: true }, - builder: (command: SlashCommandSubcommandBuilder) => { return command .setName("cancel") @@ -22,6 +21,8 @@ export default { ); }, execute: async (interaction: ChatInputCommandInteraction) => { + await deferReply(interaction, true); + // const { successColor, footerText, footerIcon } = await getEmbedConfig( // interaction.guild // ); diff --git a/src/commands/shop/modules/roles/modules/index.ts b/src/commands/shop/modules/roles/modules/index.ts deleted file mode 100644 index b9e1626..0000000 --- a/src/commands/shop/modules/roles/modules/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -import buy from "./buy"; -import cancel from "./cancel"; - -export default { - buy, - cancel, -};