♻️ counters view

This commit is contained in:
Axel Olausson Holtenäs 2022-04-13 01:22:58 +02:00
parent e67b30a015
commit 2b5c16b54a
No known key found for this signature in database
GPG key ID: 9347A5E873995701
2 changed files with 53 additions and 67 deletions

View file

@ -3,41 +3,19 @@ import { CommandInteraction } from "discord.js";
import { SlashCommandBuilder } from "@discordjs/builders"; import { SlashCommandBuilder } from "@discordjs/builders";
// Modules // Modules
import view from "./modules/view"; import moduleView from "./modules/view";
// Handlers
import logger from "../../handlers/logger";
// Function // Function
export default { export default {
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
.setName("counters") .setName("counters")
.setDescription("Manage counters.") .setDescription("Manage counters.")
.addSubcommand((subcommand) => .addSubcommand(moduleView.data),
subcommand
.setName("view")
.setDescription("View a counter.")
.addChannelOption((option) =>
option
.setName("channel")
.setDescription("The counter channel you want to view")
.setRequired(true)
)
),
async execute(interaction: CommandInteraction) { async execute(interaction: CommandInteraction) {
const { options, guild, user, commandName } = interaction; const { options } = interaction;
// Module - View
if (options?.getSubcommand() === "view") { if (options?.getSubcommand() === "view") {
// Execute Module - View return moduleView.execute(interaction);
return view(interaction);
} }
// Send debug message
return logger?.debug(
`Guild: ${guild?.id} User: ${
user?.id
} executed /${commandName} ${options?.getSubcommandGroup()} ${options?.getSubcommand()}`
);
}, },
}; };

View file

@ -1,54 +1,62 @@
// Dependencies // 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 // Configurations
import config from "../../../../config.json"; import { colors, footer } from "../../../../config.json";
// Models // Models
import counterSchema from "../../../database/schemas/counter"; import counterSchema from "../../../database/schemas/counter";
// Function // Function
export default async (interaction: CommandInteraction) => { export default {
// Destructure member data: (command: SlashCommandSubcommandBuilder) => {
const { options, guild } = interaction; 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 discordChannel = options?.getChannel("channel");
const optionChannel = options?.getChannel("channel");
const counter = await counterSchema?.findOne({ const counter = await counterSchema?.findOne({
guildId: guild?.id, guildId: guild?.id,
channelId: optionChannel?.id, channelId: discordChannel?.id,
}); });
if (!counter) { if (counter === null) {
// Create embed object return interaction?.editReply({
const embed = { embeds: [
title: ":1234: Counters [View]" as string, new MessageEmbed()
description: `${optionChannel} is not a counting channel.` as string, .setTitle("[:1234:] Counters (View)")
timestamp: new Date(), .setDescription(`${discordChannel} is not a counting channel!`)
color: config?.colors?.error as ColorResolvable, .setTimestamp(new Date())
footer: { .setColor(colors?.error as ColorResolvable)
iconURL: config?.footer?.icon as string, .setFooter({ text: footer?.text, iconURL: footer?.icon }),
text: config?.footer?.text as string, ],
}, });
}; }
// Send interaction reply return interaction?.editReply({
return interaction?.editReply({ embeds: [embed] }); embeds: [
} new MessageEmbed()
.setTitle("[:1234:] Counters (View)")
// Embed object .setDescription(
const embed = { `${discordChannel} is currently at number ${counter?.counter}.`
title: ":1234: Counters [View]" as string, )
color: config.colors.success as ColorResolvable, .setTimestamp(new Date())
description: `${optionChannel} is currently at number ${counter?.counter}.`, .setColor(colors?.success as ColorResolvable)
timestamp: new Date(), .setFooter({ text: footer?.text, iconURL: footer?.icon }),
footer: { ],
iconURL: config?.footer?.icon as string, });
text: config?.footer?.text as string, },
},
};
// Send interaction reply
return interaction?.editReply({ embeds: [embed] });
}; };