🎨 Credits Command is now using guard classes

This commit is contained in:
Axel Olausson Holtenäs 2022-10-21 16:15:49 +02:00
parent dd5ed64e1a
commit be500e7f34
6 changed files with 27 additions and 22 deletions

View file

@ -2,34 +2,38 @@ import { SlashCommandBuilder } from "@discordjs/builders";
import { ChatInputCommandInteraction } from "discord.js"; import { ChatInputCommandInteraction } from "discord.js";
import logger from "../../middlewares/logger"; import logger from "../../middlewares/logger";
import modules from "./modules"; // Modules
import moduleBalance from "./modules/balance";
import moduleGift from "./modules/gift";
import moduleTop from "./modules/top";
import moduleWork from "./modules/work";
export const builder = new SlashCommandBuilder() export const builder = new SlashCommandBuilder()
.setName("credits") .setName("credits")
.setDescription("Manage your credits.") .setDescription("Manage your credits.")
.setDMPermission(false)
.addSubcommand(modules.balance.builder) // Modules
.addSubcommand(modules.gift.builder) .addSubcommand(moduleBalance.builder)
.addSubcommand(modules.top.builder) .addSubcommand(moduleGift.builder)
.addSubcommand(modules.work.builder); .addSubcommand(moduleTop.builder)
.addSubcommand(moduleWork.builder);
export const moduleData = modules;
export const execute = async (interaction: ChatInputCommandInteraction) => { export const execute = async (interaction: ChatInputCommandInteraction) => {
const { options } = interaction; const { options } = interaction;
switch (options.getSubcommand()) { switch (options.getSubcommand()) {
case "balance": case "balance":
await modules.balance.execute(interaction); await moduleBalance.execute(interaction);
break; break;
case "gift": case "gift":
await modules.gift.execute(interaction); await moduleGift.execute(interaction);
break; break;
case "top": case "top":
await modules.top.execute(interaction); await moduleTop.execute(interaction);
break; break;
case "work": case "work":
await modules.work.execute(interaction); await moduleWork.execute(interaction);
break; break;
default: default:
logger.silly(`Unknown subcommand ${options.getSubcommand()}`); logger.silly(`Unknown subcommand ${options.getSubcommand()}`);

View file

@ -1,11 +1,11 @@
import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import { CommandInteraction, EmbedBuilder } from "discord.js"; import { CommandInteraction, EmbedBuilder } from "discord.js";
import prisma from "../../../../handlers/database"; import prisma from "../../../../handlers/database";
import deferReply from "../../../../handlers/deferReply";
import getEmbedConfig from "../../../../helpers/getEmbedData"; import getEmbedConfig from "../../../../helpers/getEmbedData";
import logger from "../../../../middlewares/logger"; import logger from "../../../../middlewares/logger";
export default { export default {
metadata: { guildOnly: true, ephemeral: true },
builder: (command: SlashCommandSubcommandBuilder) => { builder: (command: SlashCommandSubcommandBuilder) => {
return command return command
.setName("balance") .setName("balance")
@ -17,6 +17,8 @@ export default {
); );
}, },
execute: async (interaction: CommandInteraction) => { execute: async (interaction: CommandInteraction) => {
await deferReply(interaction, true);
const { errorColor, successColor, footerText, footerIcon } = const { errorColor, successColor, footerText, footerIcon } =
await getEmbedConfig(interaction.guild); await getEmbedConfig(interaction.guild);
const { options, user, guild } = interaction; const { options, user, guild } = interaction;

View file

@ -7,13 +7,12 @@ import {
} from "discord.js"; } from "discord.js";
import transferCredits from "../../../../helpers/transferCredits"; import transferCredits from "../../../../helpers/transferCredits";
// Configurations // Configurations
import deferReply from "../../../../handlers/deferReply";
import getEmbedConfig from "../../../../helpers/getEmbedData"; import getEmbedConfig from "../../../../helpers/getEmbedData";
// Handlers // Handlers
// Function // Function
export default { export default {
metadata: { guildOnly: true, ephemeral: true },
builder: (command: SlashCommandSubcommandBuilder) => { builder: (command: SlashCommandSubcommandBuilder) => {
return command return command
.setName("gift") .setName("gift")
@ -35,6 +34,8 @@ export default {
); );
}, },
execute: async (interaction: ChatInputCommandInteraction) => { execute: async (interaction: ChatInputCommandInteraction) => {
await deferReply(interaction, true);
const { successColor, footerText, footerIcon } = await getEmbedConfig( const { successColor, footerText, footerIcon } = await getEmbedConfig(
interaction.guild interaction.guild
); );

View file

@ -1,6 +0,0 @@
import balance from "./balance";
import gift from "./gift";
import top from "./top";
import work from "./work";
export default { balance, gift, top, work };

View file

@ -2,6 +2,7 @@ import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import { GuildMember } from "@prisma/client"; import { GuildMember } from "@prisma/client";
import { CommandInteraction, EmbedBuilder } from "discord.js"; import { CommandInteraction, EmbedBuilder } from "discord.js";
import prisma from "../../../../handlers/database"; import prisma from "../../../../handlers/database";
import deferReply from "../../../../handlers/deferReply";
import getEmbedConfig from "../../../../helpers/getEmbedData"; import getEmbedConfig from "../../../../helpers/getEmbedData";
import logger from "../../../../middlewares/logger"; import logger from "../../../../middlewares/logger";
@ -12,6 +13,8 @@ export default {
return command.setName("top").setDescription(`View the top users`); return command.setName("top").setDescription(`View the top users`);
}, },
execute: async (interaction: CommandInteraction) => { execute: async (interaction: CommandInteraction) => {
await deferReply(interaction, false);
const { errorColor, successColor, footerText, footerIcon } = const { errorColor, successColor, footerText, footerIcon } =
await getEmbedConfig(interaction.guild); await getEmbedConfig(interaction.guild);
const { guild } = interaction; const { guild } = interaction;

View file

@ -9,15 +9,16 @@ import getEmbedConfig from "../../../../helpers/getEmbedData";
// Helpers // Helpers
// Handlers // Handlers
import prisma from "../../../../handlers/database"; import prisma from "../../../../handlers/database";
import deferReply from "../../../../handlers/deferReply";
import logger from "../../../../middlewares/logger"; import logger from "../../../../middlewares/logger";
export default { export default {
metadata: { guildOnly: true, ephemeral: true },
builder: (command: SlashCommandSubcommandBuilder) => { builder: (command: SlashCommandSubcommandBuilder) => {
return command.setName("work").setDescription(`Work to earn credits`); return command.setName("work").setDescription(`Work to earn credits`);
}, },
execute: async (interaction: CommandInteraction) => { execute: async (interaction: CommandInteraction) => {
await deferReply(interaction, true);
const { successColor, footerText, footerIcon } = await getEmbedConfig( const { successColor, footerText, footerIcon } = await getEmbedConfig(
interaction.guild interaction.guild
); // Destructure member ); // Destructure member