commands/settings/logs/attachments

pull/17/head
TheCodedProf 3 years ago
parent b493b8a75b
commit c25369c35c

@ -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, ButtonInteraction } from "discord.js";
import EmojiEmbed from "../../../utils/generateEmojiEmbed.js";
import confirmationMessage from "../../../utils/confirmationMessage.js";
import getEmojiByName from "../../../utils/getEmojiByName.js";
@ -25,10 +25,10 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
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: [
@ -41,7 +41,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
});
}
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()
@ -53,19 +53,20 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
});
}
const confirmation = await new confirmationMessage(interaction)
.setEmoji("CHANNEL.TEXT.EDIT", "CHANNEL.TEXT.DELETE")
.setEmoji("CHANNEL.TEXT.EDIT")
.setTitle("Attachment Log Channel")
.setDescription(
"This will be the channel all attachments will be sent to.\n\n" +
`Are you sure you want to set the attachment log channel to <#${channel.id}>?`
)
.setColor("Warning")
.setFailedMessage("Attachment log channel not set", "Warning", "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.attachments.channel": channel.id
});
const { log, NucleusColors, entry, renderUser, renderChannel } = client.logger;
@ -84,7 +85,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
channel: entry(channel.id, renderChannel(channel))
},
hidden: {
guild: interaction.guild.id
guild: interaction.guild!.id
}
};
log(data);
@ -114,7 +115,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
}
}
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.staff.channel;
let timedOut = false;
@ -127,7 +128,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
channel
? `Your attachment log channel is currently set to <#${channel}>`
: "This server does not have an attachment log channel" +
(client.database.premium.hasPremium(interaction.guild.id)
(await client.database.premium.hasPremium(interaction.guild!.id)
? ""
: "\n\nThis server does not have premium, so this feature is disabled")
)
@ -135,7 +136,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
.setEmoji("CHANNEL.TEXT.CREATE")
],
components: [
new ActionRowBuilder().addComponents([
new ActionRowBuilder<ButtonBuilder>().addComponents([
new ButtonBuilder()
.setCustomId("clear")
.setLabel(clicks ? "Click again to confirm" : "Reset channel")
@ -156,12 +157,12 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
continue;
}
i.deferUpdate();
if (i.component.customId === "clear") {
if ((i.component as unknown as ButtonInteraction).customId === "clear") {
clicks += 1;
if (clicks === 2) {
clicks = 0;
await client.database.guilds.write(interaction.guild.id, null, ["logging.announcements.channel"]);
channel = undefined;
await client.database.guilds.write(interaction.guild!.id, null, ["logging.announcements.channel"]);
channel = null;
}
}
}
@ -179,7 +180,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
.setFooter({ text: "Message closed" })
],
components: [
new ActionRowBuilder().addComponents([
new ActionRowBuilder<ButtonBuilder>().addComponents([
new ButtonBuilder()
.setCustomId("clear")
.setLabel("Clear")

Loading…
Cancel
Save