commands/settings/logs/*

pull/17/head
TheCodedProf 3 years ago
parent c25369c35c
commit 327016b49c

@ -1,10 +1,10 @@
import { LoadingEmbed } from "../../../utils/defaults.js"; import { LoadingEmbed } from "../../../utils/defaults.js";
import { ChannelType } from "discord-api-types/v9"; 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 EmojiEmbed from "../../../utils/generateEmojiEmbed.js";
import confirmationMessage from "../../../utils/confirmationMessage.js"; import confirmationMessage from "../../../utils/confirmationMessage.js";
import getEmojiByName from "../../../utils/getEmojiByName.js"; import getEmojiByName from "../../../utils/getEmojiByName.js";
import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import type { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import client from "../../../utils/client.js"; import client from "../../../utils/client.js";
const command = (builder: SlashCommandSubcommandBuilder) => const command = (builder: SlashCommandSubcommandBuilder) =>
@ -24,10 +24,10 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
ephemeral: true, ephemeral: true,
fetchReply: true fetchReply: true
})) as Discord.Message; })) as Discord.Message;
if (interaction.options.getChannel("channel")) { if (interaction.options.get("channel")?.channel) {
let channel; let channel;
try { try {
channel = interaction.options.getChannel("channel"); channel = interaction.options.get("channel")?.channel;
} catch { } catch {
return await interaction.editReply({ return await interaction.editReply({
embeds: [ embeds: [
@ -40,7 +40,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
}); });
} }
channel = channel as Discord.TextChannel; channel = channel as Discord.TextChannel;
if (channel.guild.id !== interaction.guild.id) { if (channel.guild.id !== interaction.guild!.id) {
return interaction.editReply({ return interaction.editReply({
embeds: [ embeds: [
new EmojiEmbed() new EmojiEmbed()
@ -52,16 +52,17 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
}); });
} }
const confirmation = await new confirmationMessage(interaction) const confirmation = await new confirmationMessage(interaction)
.setEmoji("CHANNEL.TEXT.EDIT", "CHANNEL.TEXT.DELETE") .setEmoji("CHANNEL.TEXT.EDIT")
.setTitle("Log Channel") .setTitle("Log Channel")
.setDescription(`Are you sure you want to set the log channel to <#${channel.id}>?`) .setDescription(`Are you sure you want to set the log channel to <#${channel.id}>?`)
.setColor("Warning") .setColor("Warning")
.setFailedMessage("The log channel was not changed", "Danger", "CHANNEL.TEXT.DELETE")
.setInverted(true) .setInverted(true)
.send(true); .send(true);
if (confirmation.cancelled) return; if (confirmation.cancelled) return;
if (confirmation.success) { if (confirmation.success) {
try { try {
await client.database.guilds.write(interaction.guild.id, { await client.database.guilds.write(interaction.guild!.id, {
"logging.logs.channel": channel.id "logging.logs.channel": channel.id
}); });
const { log, NucleusColors, entry, renderUser, renderChannel } = client.logger; const { log, NucleusColors, entry, renderUser, renderChannel } = client.logger;
@ -111,7 +112,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
} }
} }
let clicks = 0; 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 channel = data.logging.logs.channel;
let timedOut = false; let timedOut = false;
while (!timedOut) { while (!timedOut) {
@ -128,7 +129,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
.setEmoji("CHANNEL.TEXT.CREATE") .setEmoji("CHANNEL.TEXT.CREATE")
], ],
components: [ components: [
new ActionRowBuilder().addComponents([ new ActionRowBuilder<ButtonBuilder>().addComponents([
new ButtonBuilder() new ButtonBuilder()
.setCustomId("clear") .setCustomId("clear")
.setLabel(clicks ? "Click again to confirm" : "Reset channel") .setLabel(clicks ? "Click again to confirm" : "Reset channel")
@ -138,22 +139,23 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
]) ])
] ]
}); });
let i; let i: ButtonInteraction;
try { try {
i = await m.awaitMessageComponent({ i = await m.awaitMessageComponent({
time: 300000, time: 300000,
filter: (i) => { return i.user.id === interaction.user.id && i.channel!.id === interaction.channel!.id } filter: (i) => { return i.user.id === interaction.user.id && i.channel!.id === interaction.channel!.id }
}); }) as ButtonInteraction;
} catch (e) { } catch (e) {
timedOut = true; timedOut = true;
} }
i = i!
i.deferUpdate(); i.deferUpdate();
if (i.component.customId === "clear") { if ((i.component as ButtonComponent).customId === "clear") {
clicks += 1; clicks += 1;
if (clicks === 2) { if (clicks === 2) {
clicks = 0; clicks = 0;
await client.database.guilds.write(interaction.guild.id, null, ["logging.logs.channel"]); await client.database.guilds.write(interaction.guild!.id, null, ["logging.logs.channel"]);
channel = undefined; channel = null;
} }
} }
} }
@ -171,7 +173,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
.setFooter({ text: "Message closed" }) .setFooter({ text: "Message closed" })
], ],
components: [ components: [
new ActionRowBuilder().addComponents([ new ActionRowBuilder<ButtonBuilder>().addComponents([
new ButtonBuilder() new ButtonBuilder()
.setCustomId("clear") .setCustomId("clear")
.setLabel("Clear") .setLabel("Clear")

@ -1,6 +1,6 @@
import { LoadingEmbed } from "../../../utils/defaults.js"; import { LoadingEmbed } from "../../../utils/defaults.js";
import Discord, { CommandInteraction, Message, ActionRowBuilder, ButtonBuilder, SelectMenuBuilder, ButtonStyle } from "discord.js"; import Discord, { CommandInteraction, Message, ActionRowBuilder, ButtonBuilder, SelectMenuBuilder, ButtonStyle, StringSelectMenuBuilder, EmbedBuilder, StringSelectMenuComponent, StringSelectMenuInteraction } from "discord.js";
import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import type { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import EmojiEmbed from "../../../utils/generateEmojiEmbed.js"; import EmojiEmbed from "../../../utils/generateEmojiEmbed.js";
import client from "../../../utils/client.js"; import client from "../../../utils/client.js";
import { toHexArray, toHexInteger } from "../../../utils/calculate.js"; import { toHexArray, toHexInteger } from "../../../utils/calculate.js";
@ -40,7 +40,7 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
let m: Message; let m: Message;
let timedOut = false; let timedOut = false;
do { 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); const converted = toHexArray(config.logging.logs.toLog);
m = (await interaction.editReply({ m = (await interaction.editReply({
embeds: [ embeds: [
@ -53,21 +53,21 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
.setEmoji("CHANNEL.TEXT.CREATE") .setEmoji("CHANNEL.TEXT.CREATE")
], ],
components: [ components: [
new ActionRowBuilder().addComponents([ new ActionRowBuilder<StringSelectMenuBuilder>().addComponents([
new SelectMenuBuilder() new StringSelectMenuBuilder()
.setPlaceholder("Set events to log") .setPlaceholder("Set events to log")
.setMaxValues(Object.keys(logs).length) .setMaxValues(Object.keys(logs).length)
.setCustomId("logs") .setCustomId("logs")
.setMinValues(0) .setMinValues(0)
.setOptions( .setOptions(
Object.keys(logs).map((e, i) => ({ Object.keys(logs).map((e, i) => ({
label: logs[e], label: (logs as any)[e],
value: i.toString(), value: i.toString(),
default: converted.includes(e) default: converted.includes(e)
})) }))
) )
]), ]),
new ActionRowBuilder().addComponents([ new ActionRowBuilder<ButtonBuilder>().addComponents([
new ButtonBuilder().setLabel("Select all").setStyle(ButtonStyle.Primary).setCustomId("all"), new ButtonBuilder().setLabel("Select all").setStyle(ButtonStyle.Primary).setCustomId("all"),
new ButtonBuilder().setLabel("Select none").setStyle(ButtonStyle.Danger).setCustomId("none") new ButtonBuilder().setLabel("Select none").setStyle(ButtonStyle.Danger).setCustomId("none")
]) ])
@ -85,24 +85,24 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
} }
i.deferUpdate(); i.deferUpdate();
if (i.customId === "logs") { if (i.customId === "logs") {
const selected = i.values; const selected = (i as StringSelectMenuInteraction).values;
const newLogs = toHexInteger(selected.map((e) => Object.keys(logs)[parseInt(e)])); const newLogs = toHexInteger(selected.map((e: string) => Object.keys(logs)[parseInt(e)]!));
await client.database.guilds.write(interaction.guild.id, { await client.database.guilds.write(interaction.guild!.id, {
"logging.logs.toLog": newLogs "logging.logs.toLog": newLogs
}); });
} else if (i.customId === "all") { } else if (i.customId === "all") {
const newLogs = toHexInteger(Object.keys(logs).map((e) => e)); 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 "logging.logs.toLog": newLogs
}); });
} else if (i.customId === "none") { } 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 "logging.logs.toLog": 0
}); });
} }
} while (!timedOut); } 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; return;
}; };

@ -1,6 +1,6 @@
import { LoadingEmbed } from "../../../utils/defaults.js"; import { LoadingEmbed } from "../../../utils/defaults.js";
import { ChannelType } from "discord-api-types/v9"; 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 EmojiEmbed from "../../../utils/generateEmojiEmbed.js";
import confirmationMessage from "../../../utils/confirmationMessage.js"; import confirmationMessage from "../../../utils/confirmationMessage.js";
import getEmojiByName from "../../../utils/getEmojiByName.js"; import getEmojiByName from "../../../utils/getEmojiByName.js";
@ -26,10 +26,10 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
ephemeral: true, ephemeral: true,
fetchReply: true fetchReply: true
})) as Discord.Message; })) as Discord.Message;
if (interaction.options.getChannel("channel")) { if (interaction.options.get("channel")?.channel) {
let channel; let channel;
try { try {
channel = interaction.options.getChannel("channel"); channel = interaction.options.get("channel")?.channel;
} catch { } catch {
return await interaction.editReply({ return await interaction.editReply({
embeds: [ embeds: [
@ -54,13 +54,14 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
}); });
} }
const confirmation = await new confirmationMessage(interaction) const confirmation = await new confirmationMessage(interaction)
.setEmoji("CHANNEL.TEXT.EDIT", "CHANNEL.TEXT.DELETE") .setEmoji("CHANNEL.TEXT.EDIT")
.setTitle("Staff Notifications Channel") .setTitle("Staff Notifications Channel")
.setDescription( .setDescription(
"This will be the channel all notifications, updates, user reports etc. will be sent to.\n\n" + "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}>?` `Are you sure you want to set the staff notifications channel to <#${channel.id}>?`
) )
.setColor("Warning") .setColor("Warning")
.setFailedMessage("Staff notifications channel not set", "Warning", "CHANNEL.TEXT.DELETE")
.setInverted(true) .setInverted(true)
.send(true); .send(true);
if (confirmation.cancelled) return; if (confirmation.cancelled) return;
@ -132,7 +133,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
.setEmoji("CHANNEL.TEXT.CREATE") .setEmoji("CHANNEL.TEXT.CREATE")
], ],
components: [ components: [
new ActionRowBuilder().addComponents([ new ActionRowBuilder<ButtonBuilder>().addComponents([
new ButtonBuilder() new ButtonBuilder()
.setCustomId("clear") .setCustomId("clear")
.setLabel(clicks ? "Click again to confirm" : "Reset channel") .setLabel(clicks ? "Click again to confirm" : "Reset channel")
@ -153,12 +154,12 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
continue; continue;
} }
i.deferUpdate(); i.deferUpdate();
if ((i.component as ButtonBuilder).customId === "clear") { if ((i.component as ButtonComponent).customId === "clear") {
clicks += 1; clicks += 1;
if (clicks === 2) { if (clicks === 2) {
clicks = 0; clicks = 0;
await client.database.guilds.write(interaction.guild.id, null, ["logging.staff.channel"]); 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<unknown> => {
.setFooter({ text: "Message closed" }) .setFooter({ text: "Message closed" })
], ],
components: [ components: [
new ActionRowBuilder().addComponents([ new ActionRowBuilder<ButtonBuilder>().addComponents([
new ButtonBuilder() new ButtonBuilder()
.setCustomId("clear") .setCustomId("clear")
.setLabel("Clear") .setLabel("Clear")

Loading…
Cancel
Save