From 2b5c16b54a81c5c3c1e48d3143cbcd34b963c605 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 13 Apr 2022 01:22:58 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20counters=20view?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/counters/index.ts | 30 ++------- src/commands/counters/modules/view.ts | 90 +++++++++++++++------------ 2 files changed, 53 insertions(+), 67 deletions(-) diff --git a/src/commands/counters/index.ts b/src/commands/counters/index.ts index 3d3542e..485a63d 100644 --- a/src/commands/counters/index.ts +++ b/src/commands/counters/index.ts @@ -3,41 +3,19 @@ import { CommandInteraction } from "discord.js"; import { SlashCommandBuilder } from "@discordjs/builders"; // Modules -import view from "./modules/view"; - -// Handlers -import logger from "../../handlers/logger"; +import moduleView from "./modules/view"; // Function export default { data: new SlashCommandBuilder() .setName("counters") .setDescription("Manage counters.") - .addSubcommand((subcommand) => - subcommand - .setName("view") - .setDescription("View a counter.") - .addChannelOption((option) => - option - .setName("channel") - .setDescription("The counter channel you want to view") - .setRequired(true) - ) - ), + .addSubcommand(moduleView.data), async execute(interaction: CommandInteraction) { - const { options, guild, user, commandName } = interaction; + const { options } = interaction; - // Module - View if (options?.getSubcommand() === "view") { - // Execute Module - View - return view(interaction); + return moduleView.execute(interaction); } - - // Send debug message - return logger?.debug( - `Guild: ${guild?.id} User: ${ - user?.id - } executed /${commandName} ${options?.getSubcommandGroup()} ${options?.getSubcommand()}` - ); }, }; diff --git a/src/commands/counters/modules/view.ts b/src/commands/counters/modules/view.ts index 1528659..74b8168 100644 --- a/src/commands/counters/modules/view.ts +++ b/src/commands/counters/modules/view.ts @@ -1,54 +1,62 @@ // Dependencies -import { CommandInteraction, ColorResolvable } from "discord.js"; +import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; +import { ChannelType } from "discord-api-types/v10"; +import { CommandInteraction, ColorResolvable, MessageEmbed } from "discord.js"; // Configurations -import config from "../../../../config.json"; +import { colors, footer } from "../../../../config.json"; // Models import counterSchema from "../../../database/schemas/counter"; // Function -export default async (interaction: CommandInteraction) => { - // Destructure member - const { options, guild } = interaction; +export default { + data: (command: SlashCommandSubcommandBuilder) => { + return command + .setName("view") + .setDescription("View a counter.") + .addChannelOption((option) => + option + .setName("channel") + .setDescription("The counter channel you want to view") + .setRequired(true) + .addChannelType(ChannelType.GuildText as number) + ); + }, + execute: async (interaction: CommandInteraction) => { + const { options, guild } = interaction; - // Get options - const optionChannel = options?.getChannel("channel"); + const discordChannel = options?.getChannel("channel"); - const counter = await counterSchema?.findOne({ - guildId: guild?.id, - channelId: optionChannel?.id, - }); + const counter = await counterSchema?.findOne({ + guildId: guild?.id, + channelId: discordChannel?.id, + }); - if (!counter) { - // Create embed object - const embed = { - title: ":1234: Counters [View]" as string, - description: `${optionChannel} is not a counting channel.` as string, - timestamp: new Date(), - color: config?.colors?.error as ColorResolvable, - footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, - }, - }; + if (counter === null) { + return interaction?.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:1234:] Counters (View)") + .setDescription(`${discordChannel} is not a counting channel!`) + .setTimestamp(new Date()) + .setColor(colors?.error as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + } - // Send interaction reply - return interaction?.editReply({ embeds: [embed] }); - } - - // Embed object - const embed = { - title: ":1234: Counters [View]" as string, - color: config.colors.success as ColorResolvable, - description: `${optionChannel} is currently at number ${counter?.counter}.`, - timestamp: new Date(), - footer: { - iconURL: config?.footer?.icon as string, - text: config?.footer?.text as string, - }, - }; - - // Send interaction reply - return interaction?.editReply({ embeds: [embed] }); + return interaction?.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:1234:] Counters (View)") + .setDescription( + `${discordChannel} is currently at number ${counter?.counter}.` + ) + .setTimestamp(new Date()) + .setColor(colors?.success as ColorResolvable) + .setFooter({ text: footer?.text, iconURL: footer?.icon }), + ], + }); + }, };