From 327016b49cbdc48e3e8b402e433b15d21ea6d87e Mon Sep 17 00:00:00 2001 From: TheCodedProf Date: Wed, 18 Jan 2023 21:48:00 -0500 Subject: [PATCH] commands/settings/logs/* --- src/commands/settings/logs/channel.ts | 32 ++++++++++++++------------- src/commands/settings/logs/events.ts | 26 +++++++++++----------- src/commands/settings/logs/staff.ts | 17 +++++++------- 3 files changed, 39 insertions(+), 36 deletions(-) diff --git a/src/commands/settings/logs/channel.ts b/src/commands/settings/logs/channel.ts index 9129841..992491a 100644 --- a/src/commands/settings/logs/channel.ts +++ b/src/commands/settings/logs/channel.ts @@ -1,10 +1,10 @@ import { LoadingEmbed } from "../../../utils/defaults.js"; import { ChannelType } from "discord-api-types/v9"; -import Discord, { CommandInteraction, ActionRowBuilder, ButtonBuilder, ButtonStyle } from "discord.js"; +import Discord, { CommandInteraction, ActionRowBuilder, ButtonBuilder, ButtonStyle, ButtonInteraction, ButtonComponent } from "discord.js"; import EmojiEmbed from "../../../utils/generateEmojiEmbed.js"; import confirmationMessage from "../../../utils/confirmationMessage.js"; import getEmojiByName from "../../../utils/getEmojiByName.js"; -import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; +import type { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import client from "../../../utils/client.js"; const command = (builder: SlashCommandSubcommandBuilder) => @@ -24,10 +24,10 @@ const callback = async (interaction: CommandInteraction): Promise => { ephemeral: true, fetchReply: true })) as Discord.Message; - if (interaction.options.getChannel("channel")) { + if (interaction.options.get("channel")?.channel) { let channel; try { - channel = interaction.options.getChannel("channel"); + channel = interaction.options.get("channel")?.channel; } catch { return await interaction.editReply({ embeds: [ @@ -40,7 +40,7 @@ const callback = async (interaction: CommandInteraction): Promise => { }); } channel = channel as Discord.TextChannel; - if (channel.guild.id !== interaction.guild.id) { + if (channel.guild.id !== interaction.guild!.id) { return interaction.editReply({ embeds: [ new EmojiEmbed() @@ -52,16 +52,17 @@ const callback = async (interaction: CommandInteraction): Promise => { }); } const confirmation = await new confirmationMessage(interaction) - .setEmoji("CHANNEL.TEXT.EDIT", "CHANNEL.TEXT.DELETE") + .setEmoji("CHANNEL.TEXT.EDIT") .setTitle("Log Channel") .setDescription(`Are you sure you want to set the log channel to <#${channel.id}>?`) .setColor("Warning") + .setFailedMessage("The log channel was not changed", "Danger", "CHANNEL.TEXT.DELETE") .setInverted(true) .send(true); if (confirmation.cancelled) return; if (confirmation.success) { try { - await client.database.guilds.write(interaction.guild.id, { + await client.database.guilds.write(interaction.guild!.id, { "logging.logs.channel": channel.id }); const { log, NucleusColors, entry, renderUser, renderChannel } = client.logger; @@ -111,7 +112,7 @@ const callback = async (interaction: CommandInteraction): Promise => { } } let clicks = 0; - const data = await client.database.guilds.read(interaction.guild.id); + const data = await client.database.guilds.read(interaction.guild!.id); let channel = data.logging.logs.channel; let timedOut = false; while (!timedOut) { @@ -128,7 +129,7 @@ const callback = async (interaction: CommandInteraction): Promise => { .setEmoji("CHANNEL.TEXT.CREATE") ], components: [ - new ActionRowBuilder().addComponents([ + new ActionRowBuilder().addComponents([ new ButtonBuilder() .setCustomId("clear") .setLabel(clicks ? "Click again to confirm" : "Reset channel") @@ -138,22 +139,23 @@ const callback = async (interaction: CommandInteraction): Promise => { ]) ] }); - let i; + let i: ButtonInteraction; try { i = await m.awaitMessageComponent({ time: 300000, filter: (i) => { return i.user.id === interaction.user.id && i.channel!.id === interaction.channel!.id } - }); + }) as ButtonInteraction; } catch (e) { timedOut = true; } + i = i! i.deferUpdate(); - if (i.component.customId === "clear") { + if ((i.component as ButtonComponent).customId === "clear") { clicks += 1; if (clicks === 2) { clicks = 0; - await client.database.guilds.write(interaction.guild.id, null, ["logging.logs.channel"]); - channel = undefined; + await client.database.guilds.write(interaction.guild!.id, null, ["logging.logs.channel"]); + channel = null; } } } @@ -171,7 +173,7 @@ const callback = async (interaction: CommandInteraction): Promise => { .setFooter({ text: "Message closed" }) ], components: [ - new ActionRowBuilder().addComponents([ + new ActionRowBuilder().addComponents([ new ButtonBuilder() .setCustomId("clear") .setLabel("Clear") diff --git a/src/commands/settings/logs/events.ts b/src/commands/settings/logs/events.ts index ae04e89..a158b19 100644 --- a/src/commands/settings/logs/events.ts +++ b/src/commands/settings/logs/events.ts @@ -1,6 +1,6 @@ import { LoadingEmbed } from "../../../utils/defaults.js"; -import Discord, { CommandInteraction, Message, ActionRowBuilder, ButtonBuilder, SelectMenuBuilder, ButtonStyle } from "discord.js"; -import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; +import Discord, { CommandInteraction, Message, ActionRowBuilder, ButtonBuilder, SelectMenuBuilder, ButtonStyle, StringSelectMenuBuilder, EmbedBuilder, StringSelectMenuComponent, StringSelectMenuInteraction } from "discord.js"; +import type { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import EmojiEmbed from "../../../utils/generateEmojiEmbed.js"; import client from "../../../utils/client.js"; import { toHexArray, toHexInteger } from "../../../utils/calculate.js"; @@ -40,7 +40,7 @@ const callback = async (interaction: CommandInteraction): Promise => { let m: Message; let timedOut = false; do { - const config = await client.database.guilds.read(interaction.guild.id); + const config = await client.database.guilds.read(interaction.guild!.id); const converted = toHexArray(config.logging.logs.toLog); m = (await interaction.editReply({ embeds: [ @@ -53,21 +53,21 @@ const callback = async (interaction: CommandInteraction): Promise => { .setEmoji("CHANNEL.TEXT.CREATE") ], components: [ - new ActionRowBuilder().addComponents([ - new SelectMenuBuilder() + new ActionRowBuilder().addComponents([ + new StringSelectMenuBuilder() .setPlaceholder("Set events to log") .setMaxValues(Object.keys(logs).length) .setCustomId("logs") .setMinValues(0) .setOptions( Object.keys(logs).map((e, i) => ({ - label: logs[e], + label: (logs as any)[e], value: i.toString(), default: converted.includes(e) })) ) ]), - new ActionRowBuilder().addComponents([ + new ActionRowBuilder().addComponents([ new ButtonBuilder().setLabel("Select all").setStyle(ButtonStyle.Primary).setCustomId("all"), new ButtonBuilder().setLabel("Select none").setStyle(ButtonStyle.Danger).setCustomId("none") ]) @@ -85,24 +85,24 @@ const callback = async (interaction: CommandInteraction): Promise => { } i.deferUpdate(); if (i.customId === "logs") { - const selected = i.values; - const newLogs = toHexInteger(selected.map((e) => Object.keys(logs)[parseInt(e)])); - await client.database.guilds.write(interaction.guild.id, { + const selected = (i as StringSelectMenuInteraction).values; + const newLogs = toHexInteger(selected.map((e: string) => Object.keys(logs)[parseInt(e)]!)); + await client.database.guilds.write(interaction.guild!.id, { "logging.logs.toLog": newLogs }); } else if (i.customId === "all") { const newLogs = toHexInteger(Object.keys(logs).map((e) => e)); - await client.database.guilds.write(interaction.guild.id, { + await client.database.guilds.write(interaction.guild!.id, { "logging.logs.toLog": newLogs }); } else if (i.customId === "none") { - await client.database.guilds.write(interaction.guild.id, { + await client.database.guilds.write(interaction.guild!.id, { "logging.logs.toLog": 0 }); } } while (!timedOut); - await interaction.editReply({ embeds: [m.embeds[0]!.setFooter({ text: "Message timed out" })] }); + await interaction.editReply({ embeds: [new EmbedBuilder(m.embeds[0]!.data).setFooter({ text: "Message timed out" })] }); return; }; diff --git a/src/commands/settings/logs/staff.ts b/src/commands/settings/logs/staff.ts index 5a23839..13125ef 100644 --- a/src/commands/settings/logs/staff.ts +++ b/src/commands/settings/logs/staff.ts @@ -1,6 +1,6 @@ import { LoadingEmbed } from "../../../utils/defaults.js"; import { ChannelType } from "discord-api-types/v9"; -import Discord, { CommandInteraction, ActionRowBuilder, ButtonBuilder, ButtonStyle } from "discord.js"; +import Discord, { CommandInteraction, ActionRowBuilder, ButtonBuilder, ButtonStyle, ButtonComponent } from "discord.js"; import EmojiEmbed from "../../../utils/generateEmojiEmbed.js"; import confirmationMessage from "../../../utils/confirmationMessage.js"; import getEmojiByName from "../../../utils/getEmojiByName.js"; @@ -26,10 +26,10 @@ const callback = async (interaction: CommandInteraction): Promise => { ephemeral: true, fetchReply: true })) as Discord.Message; - if (interaction.options.getChannel("channel")) { + if (interaction.options.get("channel")?.channel) { let channel; try { - channel = interaction.options.getChannel("channel"); + channel = interaction.options.get("channel")?.channel; } catch { return await interaction.editReply({ embeds: [ @@ -54,13 +54,14 @@ const callback = async (interaction: CommandInteraction): Promise => { }); } const confirmation = await new confirmationMessage(interaction) - .setEmoji("CHANNEL.TEXT.EDIT", "CHANNEL.TEXT.DELETE") + .setEmoji("CHANNEL.TEXT.EDIT") .setTitle("Staff Notifications Channel") .setDescription( "This will be the channel all notifications, updates, user reports etc. will be sent to.\n\n" + `Are you sure you want to set the staff notifications channel to <#${channel.id}>?` ) .setColor("Warning") + .setFailedMessage("Staff notifications channel not set", "Warning", "CHANNEL.TEXT.DELETE") .setInverted(true) .send(true); if (confirmation.cancelled) return; @@ -132,7 +133,7 @@ const callback = async (interaction: CommandInteraction): Promise => { .setEmoji("CHANNEL.TEXT.CREATE") ], components: [ - new ActionRowBuilder().addComponents([ + new ActionRowBuilder().addComponents([ new ButtonBuilder() .setCustomId("clear") .setLabel(clicks ? "Click again to confirm" : "Reset channel") @@ -153,12 +154,12 @@ const callback = async (interaction: CommandInteraction): Promise => { continue; } i.deferUpdate(); - if ((i.component as ButtonBuilder).customId === "clear") { + if ((i.component as ButtonComponent).customId === "clear") { clicks += 1; if (clicks === 2) { clicks = 0; await client.database.guilds.write(interaction.guild.id, null, ["logging.staff.channel"]); - channel = undefined; + channel = null; } } } @@ -176,7 +177,7 @@ const callback = async (interaction: CommandInteraction): Promise => { .setFooter({ text: "Message closed" }) ], components: [ - new ActionRowBuilder().addComponents([ + new ActionRowBuilder().addComponents([ new ButtonBuilder() .setCustomId("clear") .setLabel("Clear")