loads of new commands, updates and bug fixes
diff --git a/src/commands/settings/logs/_meta.ts b/src/commands/settings/logs/_meta.ts
new file mode 100644
index 0000000..15a6fd4
--- /dev/null
+++ b/src/commands/settings/logs/_meta.ts
@@ -0,0 +1,4 @@
+const name = "log";
+const description = "Settings for logging";
+
+export { name, description };
\ No newline at end of file
diff --git a/src/commands/settings/logs/channel.ts b/src/commands/settings/logs/channel.ts
new file mode 100644
index 0000000..18ed8d9
--- /dev/null
+++ b/src/commands/settings/logs/channel.ts
@@ -0,0 +1,129 @@
+import { ChannelType } from 'discord-api-types';
+import Discord, { CommandInteraction, MessageActionRow, MessageButton } from "discord.js";
+import generateEmojiEmbed from "../../../utils/generateEmojiEmbed.js";
+import confirmationMessage from "../../../utils/confirmationMessage.js";
+import getEmojiByName from "../../../utils/getEmojiByName.js";
+import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
+import { WrappedCheck } from "jshaiku";
+import client from "../../../utils/client.js";
+
+const command = (builder: SlashCommandSubcommandBuilder) =>
+ builder
+ .setName("channel")
+ .setDescription("Sets or shows the log channel")
+ .addChannelOption(option => option.setName("channel").setDescription("The channel to set the log channel to").addChannelTypes([
+ ChannelType.GuildNews, ChannelType.GuildText
+ ]))
+
+const callback = async (interaction: CommandInteraction): Promise<any> => {
+ let m;
+ m = await interaction.reply({embeds: [new generateEmojiEmbed()
+ .setTitle("Loading")
+ .setStatus("Danger")
+ .setEmoji("NUCLEUS.LOADING")
+ ], ephemeral: true, fetchReply: true});
+ if (interaction.options.getChannel("channel")) {
+ let channel
+ try {
+ channel = interaction.options.getChannel("channel")
+ } catch {
+ return await interaction.editReply({embeds: [new generateEmojiEmbed()
+ .setEmoji("CHANNEL.TEXT.DELETE")
+ .setTitle("Log Channel")
+ .setDescription("The channel you provided is not a valid channel")
+ .setStatus("Danger")
+ ]})
+ }
+ channel = channel as Discord.TextChannel
+ if (channel.guild.id != interaction.guild.id) {
+ return interaction.editReply({embeds: [new generateEmojiEmbed()
+ .setTitle("Log Channel")
+ .setDescription(`You must choose a channel in this server`)
+ .setStatus("Danger")
+ .setEmoji("CHANNEL.TEXT.DELETE")
+ ]});
+ }
+ let confirmation = await new confirmationMessage(interaction)
+ .setEmoji("CHANNEL.TEXT.EDIT")
+ .setTitle("Log Channel")
+ .setDescription(`Are you sure you want to set the log channel to <#${channel.id}>?`)
+ .setColor("Warning")
+ .setInverted(true)
+ .send(true)
+ if (confirmation.success) {
+ try {
+ await client.database.write(interaction.guild.id, {"logging.logs.channel": channel.id})
+ } catch (e) {
+ console.log(e)
+ return interaction.editReply({embeds: [new generateEmojiEmbed()
+ .setTitle("Log Channel")
+ .setDescription(`Something went wrong and the log channel could not be set`)
+ .setStatus("Danger")
+ .setEmoji("CHANNEL.TEXT.DELETE")
+ ], components: []});
+ }
+ } else {
+ return interaction.editReply({embeds: [new generateEmojiEmbed()
+ .setTitle("Log Channel")
+ .setDescription(`No changes were made`)
+ .setStatus("Success")
+ .setEmoji("CHANNEL.TEXT.CREATE")
+ ], components: []});
+ }
+ }
+ let clicks = 0;
+ let data = await client.database.read(interaction.guild.id);
+ let channel = data.logging.logs.channel;
+ while (true) {
+ await interaction.editReply({embeds: [new generateEmojiEmbed()
+ .setTitle("Log channel")
+ .setDescription(channel ? `Your log channel is currently set to <#${channel}>` : "This server does not have a log channel")
+ .setStatus("Success")
+ .setEmoji("CHANNEL.TEXT.CREATE")
+ ], components: [new MessageActionRow().addComponents([new MessageButton()
+ .setCustomId("clear")
+ .setLabel(clicks ? "Click again to confirm" : "Reset channel")
+ .setEmoji(getEmojiByName(clicks ? "TICKETS.ISSUE" : "CONTROL.CROSS", "id"))
+ .setStyle("DANGER")
+ .setDisabled(!channel)
+ ])]});
+ let i;
+ try {
+ i = await m.awaitMessageComponent({time: 600000});
+ } catch(e) { break }
+ i.deferUpdate()
+ if (i.component.customId == "clear") {
+ clicks += 1;
+ if (clicks == 2) {
+ clicks = 0;
+ await client.database.write(interaction.guild.id, {}, ["logging.logs.channel"])
+ channel = undefined;
+ }
+ } else {
+ break
+ }
+ }
+ await interaction.editReply({embeds: [new generateEmojiEmbed()
+ .setTitle("Log channel")
+ .setDescription(channel ? `Your log channel is currently set to <#${channel}>` : "This server does not have a log channel")
+ .setStatus("Success")
+ .setEmoji("CHANNEL.TEXT.CREATE")
+ .setFooter({text: "Message closed"})
+ ], components: [new MessageActionRow().addComponents([new MessageButton()
+ .setCustomId("clear")
+ .setLabel("Clear")
+ .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
+ .setStyle("SECONDARY")
+ .setDisabled(true)
+ ])]});
+}
+
+const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
+ let member = (interaction.member as Discord.GuildMember)
+ if (!member.permissions.has("MANAGE_GUILD")) throw "You must have the `manage_server` permission to use this command"
+ return true;
+}
+
+export { command };
+export { callback };
+export { check };
diff --git a/src/commands/settings/logs/events.ts b/src/commands/settings/logs/events.ts
new file mode 100644
index 0000000..dac200c
--- /dev/null
+++ b/src/commands/settings/logs/events.ts
@@ -0,0 +1,20 @@
+import { CommandInteraction } from "discord.js";
+import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
+import { WrappedCheck } from "jshaiku";
+
+const command = (builder: SlashCommandSubcommandBuilder) =>
+ builder
+ .setName("events")
+ .setDescription("Sets what events should be logged")
+
+const callback = (interaction: CommandInteraction) => {
+ interaction.reply("This command is not yet finished [settings/log/events]");
+}
+
+const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
+ return true;
+}
+
+export { command };
+export { callback };
+export { check };
\ No newline at end of file
diff --git a/src/commands/settings/logs/ignore.ts b/src/commands/settings/logs/ignore.ts
new file mode 100644
index 0000000..4b66307
--- /dev/null
+++ b/src/commands/settings/logs/ignore.ts
@@ -0,0 +1,119 @@
+import { ChannelType } from 'discord-api-types';
+import Discord, { CommandInteraction } from "discord.js";
+import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
+import generateEmojiEmbed from "../../../utils/generateEmojiEmbed.js";
+import { WrappedCheck } from "jshaiku";
+import confirmationMessage from '../../../utils/confirmationMessage.js';
+import keyValueList from '../../../utils/generateKeyValueList.js';
+import client from '../../../utils/client.js';
+
+const command = (builder: SlashCommandSubcommandBuilder) =>
+ builder
+ .setName("ignore")
+ .setDescription("Sets which users, channels and roles should be ignored")
+ .addStringOption(o => o.setName("action").setDescription("Add or remove from the list").addChoices([
+ ["Add", "add"], ["Remove", "remove"]
+ ]).setRequired(true))
+ .addChannelOption(o => o.setName("addchannel").setDescription("Add a channel that should be ignored").addChannelTypes([
+ ChannelType.GuildText, ChannelType.GuildVoice, ChannelType.GuildNews, ChannelType.GuildPublicThread, ChannelType.GuildPrivateThread, ChannelType.GuildNewsThread
+ ]))
+ .addUserOption(o => o.setName("adduser").setDescription("Add a user that should be ignored"))
+ .addRoleOption(o => o.setName("addrole").setDescription("Add a role that should be ignored"))
+
+const callback = async (interaction: CommandInteraction): Promise<any> => {
+ let channel = interaction.options.getChannel("addchannel")
+ let user = interaction.options.getUser("adduser")
+ let role = interaction.options.getRole("addrole")
+ await interaction.reply({embeds: [new generateEmojiEmbed()
+ .setTitle("Loading")
+ .setStatus("Danger")
+ .setEmoji("NUCLEUS.LOADING")
+ ], ephemeral: true, fetchReply: true});
+ if (channel || user || role) {
+ if (channel) {
+ try {
+ channel = interaction.guild.channels.cache.get(channel.id)
+ } catch {
+ return await interaction.editReply({embeds: [new generateEmojiEmbed()
+ .setEmoji("CHANNEL.TEXT.DELETE")
+ .setTitle("Logs > Ignore")
+ .setDescription("The channel you provided is not a valid channel")
+ .setStatus("Danger")
+ ]})
+ }
+ channel = channel as Discord.TextChannel
+ if (channel.guild.id != interaction.guild.id) {
+ return interaction.editReply({embeds: [new generateEmojiEmbed()
+ .setTitle("Logs > Ignore")
+ .setDescription(`You must choose a channel in this server`)
+ .setStatus("Danger")
+ .setEmoji("CHANNEL.TEXT.DELETE")
+ ]});
+ }
+ }
+ if (user) {
+ try {
+ user = interaction.guild.members.cache.get(user.id).user
+ } catch {
+ return await interaction.editReply({embeds: [new generateEmojiEmbed()
+ .setEmoji("USER.DELETE")
+ .setTitle("Logs > Ignore")
+ .setDescription("The user you provided is not a valid user")
+ .setStatus("Danger")
+ ]})
+ }
+ user = user as Discord.User
+ }
+ if (role) {
+ try {
+ role = interaction.guild.roles.cache.get(role.id)
+ } catch {
+ return await interaction.editReply({embeds: [new generateEmojiEmbed()
+ .setEmoji("ROLE.DELETE")
+ .setTitle("Logs > Ignore")
+ .setDescription("The role you provided is not a valid role")
+ .setStatus("Danger")
+ ]})
+ }
+ role = role as Discord.Role
+ if (role.guild.id != interaction.guild.id) {
+ return interaction.editReply({embeds: [new generateEmojiEmbed()
+ .setTitle("Logs > Ignore")
+ .setDescription(`You must choose a role in this server`)
+ .setStatus("Danger")
+ .setEmoji("ROLE.DELETE")
+ ]});
+ }
+ }
+ let changes = {}
+ if (channel) changes["channel"] = channel.id
+ if (user) changes["user"] = user.id
+ if (role) changes["role"] = role.id
+ let confirmation = await new confirmationMessage(interaction)
+ .setEmoji("NUCLEUS.COMMANDS.IGNORE")
+ .setTitle("Logs > Ignore")
+ .setDescription(keyValueList(changes)
+ + `Are you sure you want to **${interaction.options.getString("action") == "add" ? "add" : "remove"}** these to the ignore list?`)
+ .setColor("Warning")
+ .send(true)
+ if (confirmation.success) {
+ let data = client.database.read(interaction.guild.id)
+ if (channel) data.logging.logs.ignore.channels.concat([channel.id])
+ if (user) data.logging.logs.ignore.users.concat([user.id])
+ if (role) data.logging.logs.ignore.roles.concat([role.id])
+ if (interaction.options.getString("action") == "add") {
+ await client.database.append(interaction.guild.id, data)
+ }
+ }
+ }
+}
+
+const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
+ let member = (interaction.member as Discord.GuildMember)
+ if (!member.permissions.has("MANAGE_GUILD")) throw "You must have the `manage_server` permission to use this command"
+ return true;
+}
+
+export { command };
+export { callback };
+export { check };
\ No newline at end of file