Merge branch 'development' of github.com:ClicksMinutePer/Nucleus into development
diff --git a/src/actions/tickets/delete.ts b/src/actions/tickets/delete.ts
index a1f63d2..43e9dd2 100644
--- a/src/actions/tickets/delete.ts
+++ b/src/actions/tickets/delete.ts
@@ -9,7 +9,7 @@
     if (!interaction.guild) return;
     const config = await client.database.guilds.read(interaction.guild.id);
     const { log, NucleusColors, entry, renderUser, renderChannel, renderDelta } = client.logger;
-
+    //FIXME
     const ticketChannel = config.tickets.category;
     if (!("parent" in interaction.channel!)) {
         return await interaction.reply({
diff --git a/src/commands/nucleus/premium.ts b/src/commands/nucleus/premium.ts
index 026984d..ed4f225 100644
--- a/src/commands/nucleus/premium.ts
+++ b/src/commands/nucleus/premium.ts
@@ -1,14 +1,73 @@
-import { ActionRowBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, CommandInteraction } from "discord.js";
+import { ActionRowBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, CommandInteraction, GuildMember, StringSelectMenuBuilder } from "discord.js";
 import type { SlashCommandSubcommandBuilder } from "discord.js";
 import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
 import client from "../../utils/client.js";
 import { LoadingEmbed } from "../../utils/defaults.js";
 import getEmojiByName from "../../utils/getEmojiByName.js";
+import type { PremiumSchema } from "../../utils/database.js";
 
 const command = (builder: SlashCommandSubcommandBuilder) =>
     builder.setName("premium").setDescription("Information about Nucleus Premium");
 //TODO: Allow User to remove Premium
+
+const dmcallback = async (interaction: CommandInteraction, member: GuildMember, dbUser: PremiumSchema | null, firstDescription: string): Promise<void> => {
+
+    if(!dbUser) {
+        await interaction.editReply({embeds: [
+            new EmojiEmbed()
+                .setTitle("Premium")
+                .setDescription(`*You do not have premium! You can't activate premium on any servers.*` + firstDescription)
+                .setEmoji("NUCLEUS.LOGO")
+                .setStatus("Danger")
+        ]});
+        return;
+    }
+    const premiumGuilds = dbUser.appliesTo.map((guildID) => {
+        const guild = client.guilds.cache.get(guildID);
+        if(!guild) return undefined;
+        return guild.name;
+    });
+
+    const options = premiumGuilds.filter((guild) => guild !== undefined) as string[];
+
+    const removeRow = new ActionRowBuilder<StringSelectMenuBuilder>()
+        .addComponents(
+            new StringSelectMenuBuilder()
+                .setCustomId("currentPremium")
+                .setPlaceholder("Select a server to remove premium from")
+                .setDisabled(premiumGuilds.length === 0)
+                .addOptions(options.map((guild) => {
+                    return {label: guild, value: guild}
+                }))
+        );
+    const removeButton = new ActionRowBuilder<ButtonBuilder>()
+        .addComponents(
+            new ButtonBuilder()
+                .setCustomId("removePremium")
+                .setLabel("Remove Premium")
+                .setStyle(ButtonStyle.Danger)
+                .setDisabled(premiumGuilds.length === 0)
+        );
+
+    await interaction.editReply(
+    {
+        embeds: [
+            new EmojiEmbed()
+                .setTitle("Premium")
+                .setDescription(`*You have premium on the following servers:*` + firstDescription)
+                .setEmoji("NUCLEUS.LOGO")
+                .setStatus("Success")
+        ],
+        components: [removeRow, removeButton]
+    });
+
+    //TODO Finish this.
+
+
+}
+
 const callback = async (interaction: CommandInteraction): Promise<void> => {
+
     await interaction.reply({embeds: LoadingEmbed, ephemeral: true})
     const member = await (await interaction.client.guilds.fetch("684492926528651336")).members.fetch(interaction.user.id).catch(() => {
         interaction.editReply({ embeds: [
@@ -44,12 +103,14 @@
         premium = `**You can't give servers premium anymore because your subscription ended or was cancelled.** To get premium again please subscribe in the Clicks server`
         count = 0;
     }
+    if(!interaction.guild) return await dmcallback(interaction, member, dbMember, firstDescription);
     const hasPremium = await client.database.premium.hasPremium(interaction.guild!.id);
     let premiumGuild = ""
-    if (hasPremium) { //FIXME: Check how user applied premium
-        premiumGuild = `**This server has premium! It was ${hasPremium[2] === 3 ? `automatically applied by <@${hasPremium[1]}>` : `given by <@${hasPremium[1]}>`}**\n\n`
+    if (hasPremium) {
+        premiumGuild = `**This server has premium! It was ${hasPremium[2] === 3 && hasPremium[3] ? `automatically applied by <@${hasPremium[1]}>` : `given by <@${hasPremium[1]}>`}**\n\n`
     }
 
+
     const components: ActionRowBuilder<ButtonBuilder>[] = []
     if (level === 0 || dbMember?.expiresAt) {
         components.push(
diff --git a/src/premium/createTranscript.ts b/src/premium/createTranscript.ts
index 88a8e6e..acd641b 100644
--- a/src/premium/createTranscript.ts
+++ b/src/premium/createTranscript.ts
@@ -181,9 +181,11 @@
 
         if (message.stickers.size > 0) msg.stickerURLs = message.stickers.map(sticker => sticker.url);
         if (message.reference) msg.referencedMessage = [message.reference.guildId ?? "", message.reference.channelId, message.reference.messageId ?? ""];
-
+        newOut.messages.push(msg);
     });
 
+    console.log(newOut);
+
     const topic = interaction.channel.topic;
     let member: GuildMember | null = null;
     if (topic !== null) {
diff --git a/src/utils/database.ts b/src/utils/database.ts
index e7336d0..48d0077 100644
--- a/src/utils/database.ts
+++ b/src/utils/database.ts
@@ -246,12 +246,12 @@
         await this.premium.insertOne({ user: user, appliesTo: [], level: level });
     }
 
-    async hasPremium(guild: string): Promise<[boolean, string, number] | null> {
+    async hasPremium(guild: string): Promise<[boolean, string, number, boolean] | null> {
         const entries = await this.premium.find({}).toArray();
         const members = await (await client.guilds.fetch(guild)).members.fetch()
         for(const {user} of entries) {
             const member = members.get(user);
-            if(member) {
+            if(member) { //TODO: Notify user if they've given premium to a server that has since gotten premium via a mod.
                 const modPerms = //TODO: Create list in config for perms
                             member.permissions.has("Administrator") ||
                             member.permissions.has("ManageChannels") ||
@@ -265,7 +265,7 @@
                             member.permissions.has("ManageMessages") ||
                             member.permissions.has("ManageThreads")
                 const entry = entries.find(e => e.user === member.id);
-                if(entry && (entry.level === 3) && modPerms) return [true, member.id, entry.level];
+                if(entry && (entry.level === 3) && modPerms) return [true, member.id, entry.level, true];
             }
         }
         const entry = await this.premium.findOne({
@@ -275,7 +275,7 @@
                 }
             }
         });
-        return entry ? [true, entry.user, entry.level] : null;
+        return entry ? [true, entry.user, entry.level, false] : null;
     }
 
     async fetchUser(user: string): Promise<PremiumSchema | null> {