🎨 Shop Command is now using guard classes

This commit is contained in:
Axel Olausson Holtenäs 2022-10-21 16:42:15 +02:00
parent 6589ac3ba3
commit 0816d0abe2
7 changed files with 52 additions and 57 deletions

View file

@ -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: {

View file

@ -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;

View file

@ -1,4 +0,0 @@
import cpgg from "./cpgg";
import * as roles from "./roles";
export default { cpgg, roles };

View file

@ -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);
}
},
};

View file

@ -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
// );

View file

@ -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
// );

View file

@ -1,7 +0,0 @@
import buy from "./buy";
import cancel from "./cancel";
export default {
buy,
cancel,
};