guess who forgot to add files
diff --git a/src/commands/settings/stats/_meta.ts b/src/commands/settings/stats/_meta.ts
new file mode 100644
index 0000000..7443a9e
--- /dev/null
+++ b/src/commands/settings/stats/_meta.ts
@@ -0,0 +1,4 @@
+const name = "stats";
+const description = "Settings for stats channels";
+
+export { name, description };
\ No newline at end of file
diff --git a/src/commands/settings/stats/remove.ts b/src/commands/settings/stats/remove.ts
new file mode 100644
index 0000000..8e3a64a
--- /dev/null
+++ b/src/commands/settings/stats/remove.ts
@@ -0,0 +1,120 @@
+import { ChannelType } from 'discord-api-types';
+import Discord, { CommandInteraction, MessageActionRow, MessageButton } 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 { WrappedCheck } from "jshaiku";
+import client from "../../../utils/client.js";
+
+const command = (builder: SlashCommandSubcommandBuilder) =>
+ builder
+ .setName("remove")
+ .setDescription("Stops updating channels when a member joins or leaves")
+ .addChannelOption(option => option.setName("channel").setDescription("The channel to stop updating").addChannelTypes([
+ ChannelType.GuildNews, ChannelType.GuildText
+ ]).setRequired(true))
+
+const callback = async (interaction: CommandInteraction): Promise<any> => {
+ let m;
+ m = await interaction.reply({embeds: [new EmojiEmbed()
+ .setTitle("Loading")
+ .setStatus("Danger")
+ .setEmoji("NUCLEUS.LOADING")
+ ], ephemeral: true, fetchReply: true});
+ if (interaction.options.getChannel("channel")) {
+ let config = client.database.guilds.read(interaction.guild.id);
+ let channel
+ try {
+ channel = interaction.options.getChannel("channel")
+ } catch {
+ return await interaction.editReply({embeds: [new EmojiEmbed()
+ .setEmoji("CHANNEL.TEXT.DELETE")
+ .setTitle("Stats 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 EmojiEmbed()
+ .setTitle("Stats Channel")
+ .setDescription(`You must choose a channel in this server`)
+ .setStatus("Danger")
+ .setEmoji("CHANNEL.TEXT.DELETE")
+ ]});
+ }
+ // check if the channel is not in the list
+ let allow = false;
+ for (let c of config.stats) { if (c.channel == channel.id) allow = true; }
+ if (!allow) {
+ return interaction.editReply({embeds: [new EmojiEmbed()
+ .setTitle("Stats Channel")
+ .setDescription(`That channel is not a stats channel`)
+ .setStatus("Danger")
+ .setEmoji("CHANNEL.TEXT.DELETE")
+ ]});
+ }
+ let confirmation = await new confirmationMessage(interaction)
+ .setEmoji("CHANNEL.TEXT.EDIT")
+ .setTitle("Stats Channel")
+ .setDescription(`Are you sure you want to stop <#${channel.id}> updating?`)
+ .setColor("Warning")
+ .setInverted(true)
+ .send(true)
+ if (confirmation.cancelled) return
+ if (confirmation.success) {
+ try {
+ let channel = interaction.options.getChannel("channel")
+ await client.database.guilds.write(interaction.guild.id, {}, [`stats.${channel.id}`]);
+ const { log, NucleusColors, entry, renderUser, renderChannel } = client.logger
+ try {
+ let data = {
+ meta:{
+ type: 'statsChannelUpdate',
+ displayName: 'Stats Channel Removed',
+ calculateType: 'nucleusSettingsUpdated',
+ color: NucleusColors.red,
+ emoji: "CHANNEL.TEXT.EDIT",
+ timestamp: new Date().getTime()
+ },
+ list: {
+ memberId: entry(interaction.user.id, `\`${interaction.user.id}\``),
+ changedBy: entry(interaction.user.id, renderUser(interaction.user)),
+ channel: entry(channel.id, renderChannel(channel)),
+ },
+ hidden: {
+ guild: interaction.guild.id
+ }
+ }
+ log(data);
+ } catch {}
+ } catch (e) {
+ console.log(e)
+ return interaction.editReply({embeds: [new EmojiEmbed()
+ .setTitle("Stats Channel")
+ .setDescription(`Something went wrong and the stats channel could not be reset`)
+ .setStatus("Danger")
+ .setEmoji("CHANNEL.TEXT.DELETE")
+ ], components: []});
+ }
+ } else {
+ return interaction.editReply({embeds: [new EmojiEmbed()
+ .setTitle("Stats Channel")
+ .setDescription(`No changes were made`)
+ .setStatus("Success")
+ .setEmoji("CHANNEL.TEXT.CREATE")
+ ], components: []});
+ }
+ }
+}
+
+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/stats/set.ts b/src/commands/settings/stats/set.ts
new file mode 100644
index 0000000..10c3011
--- /dev/null
+++ b/src/commands/settings/stats/set.ts
@@ -0,0 +1,126 @@
+import { ChannelType } from 'discord-api-types';
+import Discord, { CommandInteraction, MessageActionRow, MessageButton } 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 { WrappedCheck } from "jshaiku";
+import client from "../../../utils/client.js";
+import convertCurlyBracketString from '../../../utils/convertCurlyBracketString.js';
+import {callback as statsChannelAddCallback} from "../../../reflex/statsChannelUpdate.js";
+
+const command = (builder: SlashCommandSubcommandBuilder) =>
+ builder
+ .setName("set")
+ .setDescription("Adds or edits a channel which will update when members join or leave")
+ .addChannelOption(option => option.setName("channel").setDescription("The channel to modify").addChannelTypes([
+ ChannelType.GuildNews, ChannelType.GuildText
+ ]).setRequired(true))
+ .addStringOption(option => option.setName("name").setDescription("The channel name").setRequired(true).setAutocomplete(true))
+
+const callback = async (interaction: CommandInteraction): Promise<any> => {
+ console.log(interaction.options.getString("name"))
+ let m;
+ m = await interaction.reply({embeds: [new EmojiEmbed()
+ .setTitle("Loading")
+ .setStatus("Danger")
+ .setEmoji("NUCLEUS.LOADING")
+ ], ephemeral: true, fetchReply: true});
+ if (interaction.options.getChannel("channel")) {
+ let config = client.database.guilds.read(interaction.guild.id);
+ let channel
+ try {
+ channel = interaction.options.getChannel("channel")
+ } catch {
+ return await interaction.editReply({embeds: [new EmojiEmbed()
+ .setEmoji("CHANNEL.TEXT.DELETE")
+ .setTitle("Stats 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 EmojiEmbed()
+ .setTitle("Stats Channel")
+ .setDescription(`You must choose a channel in this server`)
+ .setStatus("Danger")
+ .setEmoji("CHANNEL.TEXT.DELETE")
+ ]});
+ }
+ let newName = await convertCurlyBracketString(interaction.options.getString("name"), null, null, interaction.guild.name, interaction.guild.members)
+ if (interaction.options.getChannel("channel").type === "GUILD_TEXT") {
+ newName = newName.toLowerCase().replace(/[\s]/g, "-")
+ }
+ let confirmation = await new confirmationMessage(interaction)
+ .setEmoji("CHANNEL.TEXT.EDIT")
+ .setTitle("Stats Channel")
+ .setDescription(`Are you sure you want to set <#${channel.id}> to a stats channel?\n\n*Preview: ${newName}*`)
+ .setColor("Warning")
+ .setInverted(true)
+ .send(true)
+ if (confirmation.cancelled) return
+ if (confirmation.success) {
+ try {
+ let name = interaction.options.getString("name")
+ let channel = interaction.options.getChannel("channel")
+ await client.database.guilds.write(interaction.guild.id, {[`stats.${channel.id}`]: {name: name, enabled: true}});
+ const { log, NucleusColors, entry, renderUser, renderChannel } = client.logger
+ try {
+ let data = {
+ meta:{
+ type: 'statsChannelUpdate',
+ displayName: 'Stats Channel Updated',
+ calculateType: 'nucleusSettingsUpdated',
+ color: NucleusColors.yellow,
+ emoji: "CHANNEL.TEXT.EDIT",
+ timestamp: new Date().getTime()
+ },
+ list: {
+ memberId: entry(interaction.user.id, `\`${interaction.user.id}\``),
+ changedBy: entry(interaction.user.id, renderUser(interaction.user)),
+ channel: entry(channel.id, renderChannel(channel)),
+ name: entry(interaction.options.getString("name"), `\`${interaction.options.getString("name")}\``)
+ },
+ hidden: {
+ guild: interaction.guild.id
+ }
+ }
+ log(data);
+ } catch {}
+ } catch (e) {
+ console.log(e)
+ return interaction.editReply({embeds: [new EmojiEmbed()
+ .setTitle("Stats Channel")
+ .setDescription(`Something went wrong and the stats channel could not be set`)
+ .setStatus("Danger")
+ .setEmoji("CHANNEL.TEXT.DELETE")
+ ], components: []});
+ }
+ } else {
+ return interaction.editReply({embeds: [new EmojiEmbed()
+ .setTitle("Stats Channel")
+ .setDescription(`No changes were made`)
+ .setStatus("Success")
+ .setEmoji("CHANNEL.TEXT.CREATE")
+ ], components: []});
+ }
+ await statsChannelAddCallback(client, interaction.member);
+ return interaction.editReply({embeds: [new EmojiEmbed()
+ .setTitle("Stats Channel")
+ .setDescription(`The stats channel has been set to <#${channel.id}>`)
+ .setStatus("Success")
+ .setEmoji("CHANNEL.TEXT.CREATE")
+ ], components: []});
+ }
+}
+
+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 };