From df09fe87873927fa29bb9af5b13fa41916db7bd5 Mon Sep 17 00:00:00 2001 From: powermaker450 Date: Thu, 17 Oct 2024 19:15:52 -0400 Subject: [PATCH] Make logging channel optional --- src/commands/confess.ts | 2 +- src/commands/setup.ts | 46 ++++++++++++++++++++++++++++++++++++----- src/main.ts | 3 +-- src/storeman/types.ts | 2 +- 4 files changed, 44 insertions(+), 9 deletions(-) diff --git a/src/commands/confess.ts b/src/commands/confess.ts index 769b04a..d858346 100644 --- a/src/commands/confess.ts +++ b/src/commands/confess.ts @@ -153,7 +153,7 @@ export async function execute(interaction: ChatInputCommandInteraction) { components: [actionRow] }); - await (BotClient.channels.cache.get(adminChannel!) as TextChannel).send({ + adminChannel && await (BotClient.channels.cache.get(adminChannel!) as TextChannel).send({ embeds: [adminConfessionEmbed] }); diff --git a/src/commands/setup.ts b/src/commands/setup.ts index 7594fe6..4be52e9 100644 --- a/src/commands/setup.ts +++ b/src/commands/setup.ts @@ -18,6 +18,8 @@ import { ActionRowBuilder, + ButtonBuilder, + ButtonStyle, ChannelSelectMenuBuilder, ChannelType, CommandInteraction, @@ -51,9 +53,17 @@ export async function execute(interaction: CommandInteraction) { .setCustomId("channels") .setPlaceholder("Choose a channel"); + const skipButton = new ButtonBuilder() + .setCustomId("skipModChannel") + .setLabel("Skip") + .setStyle(ButtonStyle.Secondary) + const channelRow = new ActionRowBuilder().addComponents(channelList); + const buttonRow = new ActionRowBuilder() + .addComponents(skipButton); + try { const response = await interaction.reply({ content: `# Let's get started, ${interaction.user.displayName}!\nFirst, let's choose a channel for your confessions.`, @@ -67,7 +77,7 @@ export async function execute(interaction: CommandInteraction) { }); collector.on("collect", async i => { - confessChannel = i.values[0]; + [ confessChannel ] = i.values; await i.update({ content: "Awesome!", @@ -89,7 +99,7 @@ export async function execute(interaction: CommandInteraction) { const logResponse = await interaction.followUp({ content: "# Now, select a logging channel, for moderation purposes.", ephemeral: true, - components: [logChannelRow] + components: [logChannelRow, buttonRow] }); const logCollector = logResponse.createMessageComponentCollector({ @@ -97,8 +107,15 @@ export async function execute(interaction: CommandInteraction) { time: 45_000 }); + const skipCollector = logResponse.createMessageComponentCollector({ + componentType: ComponentType.Button, + time: 45_000 + }); + + let skipped = false; + logCollector.on("collect", async ij => { - logChannel = ij.values[0]; + [ logChannel ] = ij.values; await ij.update({ content: "Setup Complete!", @@ -112,11 +129,30 @@ export async function execute(interaction: CommandInteraction) { }); logCollector.stop(); + skipCollector.stop(); }); + skipCollector.on("collect", async ik => { + if (ik.customId === "skipModChannel") { + await ik.update({ + content: "Setup complete!", + components: [] + }); + + dt.setup(guildId!, { + confessChannel: confessChannel, + bans: [] + }); + + skipped = true; + logCollector.stop(); + skipCollector.stop(); + } + }) + logCollector.on("end", content => { - // If there is no content, follow up with an error message. - !content.size && + // If there is no content and the channel hasn't been skipped, follow up with an error message. + (!content.size && !skipped) && interaction.followUp({ content: "No channel selected. Please try again.", ephemeral: true, diff --git a/src/main.ts b/src/main.ts index 611e1c3..db1baf1 100644 --- a/src/main.ts +++ b/src/main.ts @@ -21,7 +21,6 @@ import { ButtonBuilder, ButtonStyle, ChatInputCommandInteraction, - ComponentType, EmbedBuilder, Events, TextChannel @@ -180,7 +179,7 @@ BotClient.on(Events.InteractionCreate, async interaction => { components: [actionRow] }); - await (BotClient.channels.cache.get(adminChannel!) as TextChannel).send({ + adminChannel && await (BotClient.channels.cache.get(adminChannel!) as TextChannel).send({ embeds: [adminConfessionEmbed] }); diff --git a/src/storeman/types.ts b/src/storeman/types.ts index b1e4845..78e2974 100644 --- a/src/storeman/types.ts +++ b/src/storeman/types.ts @@ -32,7 +32,7 @@ export interface ConfessionBan { export interface GuildSettings { confessChannel: string; - modChannel: string; + modChannel?: string; bans: ConfessionBan[]; }