yees

Co-authored-by: PineappleFan <PineaFan@users.noreply.github.com>
Co-authored-by: Skyler <skyler3665@gmail.com>
diff --git a/src/premium/createTranscript.ts b/src/premium/createTranscript.ts
index acd641b..20b790a 100644
--- a/src/premium/createTranscript.ts
+++ b/src/premium/createTranscript.ts
@@ -8,7 +8,8 @@
     TextChannel,
     ButtonStyle,
     User,
-    ComponentType
+    ComponentType,
+    ThreadChannel
 } from "discord.js";
 import EmojiEmbed from "../utils/generateEmojiEmbed.js";
 import getEmojiByName from "../utils/getEmojiByName.js";
@@ -78,14 +79,21 @@
     type: "ticket" | "purge"
     guild: string;
     channel: string;
+    for: TranscriptAuthor
     messages: TranscriptMessage[];
     createdTimestamp: number;
     createdBy: TranscriptAuthor;
 }
 
+const noTopic = new EmojiEmbed()
+    .setTitle("User not found")
+    .setDescription("There is no user associated with this ticket.")
+    .setStatus("Danger")
+    .setEmoji("CONTROL.BLOCKCROSS")
+
 export default async function (interaction: CommandInteraction | MessageComponentInteraction) {
     if (interaction.channel === null) return;
-    if (!(interaction.channel instanceof TextChannel)) return;
+    if (!(interaction.channel instanceof TextChannel || interaction.channel instanceof ThreadChannel)) return;
     const { log, NucleusColors, entry, renderUser, renderDelta } = client.logger;
 
     let messages: Message[] = [];
@@ -98,6 +106,13 @@
         messages = messages.concat(Array.from(deleted.values() as Iterable<Message>));
         if (messages.length === 1) messageException(interaction.guild!.id, interaction.channel.id, messages[0]!.id)
     } while (deletedCount === 100);
+    messages = messages.filter(message => !(
+        message.components.some(
+            component => component.components.some(
+                child => child.customId?.includes("transcript") ?? false
+            )
+        )
+    ));
 
     let out = "";
     messages.reverse().forEach((message) => {
@@ -116,8 +131,30 @@
 
     const interactionMember = await interaction.guild?.members.fetch(interaction.user.id)
 
+    let topic
+    let member: GuildMember | null = null;
+    if (interaction.channel instanceof TextChannel) {
+        topic = interaction.channel.topic;
+        if (topic === null) return await interaction.reply({ embeds: [noTopic] });
+        member = interaction.guild!.members.cache.get(topic.split(" ")[1]!) ?? null;
+    } else {
+        topic = interaction.channel.name;
+        const split = topic.split("-").map(p => p.trim()) as [string, string, string];
+        member = interaction.guild!.members.cache.get(split[1]) ?? null;
+        if (member === null) return await interaction.reply({ embeds: [noTopic] });
+    }
+
+
     const newOut: Transcript = {
         type: "ticket",
+        for: {
+            username: member!.user.username,
+            discriminator: parseInt(member!.user.discriminator),
+            id: member!.user.id,
+            topRole: {
+                color: member!.roles.highest.color
+            }
+        },
         guild: interaction.guild!.id,
         channel: interaction.channel!.id,
         messages: [],
@@ -184,14 +221,8 @@
         newOut.messages.push(msg);
     });
 
-    console.log(newOut);
-
-    const topic = interaction.channel.topic;
-    let member: GuildMember | null = null;
-    if (topic !== null) {
-        const part = topic.split(" ")[0] ?? null;
-        if (part !== null) member = interaction.guild!.members.cache.get(part) ?? null;
-    }
+    const code = await client.database.transcripts.create(newOut);
+    if(!code) return await interaction.reply({embeds: [new EmojiEmbed().setTitle("Error").setDescription("An error occurred while creating the transcript.").setStatus("Danger").setEmoji("CONTROL.BLOCKCROSS")]})
     let m: Message;
     if (out !== "") {
         const url = await pbClient.createPaste({
@@ -200,7 +231,7 @@
             name:
                 `Ticket Transcript ${
                     member ? "for " + member.user.username + "#" + member.user.discriminator + " " : ""
-                }` + `(Created at ${new Date(interaction.channel.createdTimestamp).toDateString()})`,
+                }` + `(Created at ${new Date(interaction.channel.createdTimestamp!).toDateString()})`,
             publicity: Publicity.Unlisted
         });
         const guildConfig = await client.database.guilds.read(interaction.guild!.id);