From 63276257d217e903d543015cf0cbac58ffaf744d Mon Sep 17 00:00:00 2001
From: Toastie <toastie@toastiet0ast.com>
Date: Thu, 6 Feb 2025 15:22:19 +1300
Subject: [PATCH] Fixed transcript command not being able to send old html
 transcripts

---
 Commands/TranscriptCommand.cs | 42 ++++++++++++++++-------------------
 1 file changed, 19 insertions(+), 23 deletions(-)

diff --git a/Commands/TranscriptCommand.cs b/Commands/TranscriptCommand.cs
index 5a1ea90..720922a 100644
--- a/Commands/TranscriptCommand.cs
+++ b/Commands/TranscriptCommand.cs
@@ -83,18 +83,22 @@ public class TranscriptCommand
 
         string fileName = Transcriber.GetZipFilename(ticket.id);
         string filePath = Transcriber.GetZipPath(ticket.id);
-        long zipSize = 0;
+        bool zipTooLarge = false;
 
-        // If the zip transcript doesn't exist, use the html file.
+        // If the zip transcript doesn't exist or is too large, use the html file.
         try
         {
-            FileInfo fileInfo = new FileInfo(filePath);
-            if (!fileInfo.Exists || fileInfo.Length >= 26214400)
+            FileInfo zipFile = new(filePath);
+            if (!zipFile.Exists || zipFile.Length >= 26214400)
             {
                 fileName = Transcriber.GetHTMLFilename(ticket.id);
                 filePath = Transcriber.GetHtmlPath(ticket.id);
             }
-            zipSize = fileInfo.Length;
+
+            if (zipFile.Exists && zipFile.Length >= 26214400)
+            {
+                zipTooLarge = true;
+            }
         }
         catch (Exception e)
         {
@@ -121,7 +125,7 @@ public class TranscriptCommand
 
         try
         {
-            await using FileStream file = new FileStream(filePath, FileMode.Open, FileAccess.Read);
+            await using FileStream file = new(filePath, FileMode.Open, FileAccess.Read);
             await LogChannel.Success("Transcript generated by " + command.User.Mention + ".", ticket.id, new Utilities.File(fileName, file));
         }
         catch (Exception e)
@@ -129,26 +133,14 @@ public class TranscriptCommand
             Logger.Error("Failed to log transcript generation.", e);
         }
 
-        if (await SendDirectMessage(command, fileName, filePath, zipSize, ticket.id))
-        {
-            await command.EditResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
-            {
-                Color = DiscordColor.Green,
-                Description = "Transcript sent!\n"
-            }));
-        }
-    }
-
-    private static async Task<bool> SendDirectMessage(SlashCommandContext command, string fileName, string filePath, long zipSize, uint ticketID)
-    {
         try
         {
             // Send transcript in a direct message
-            await using FileStream file = new FileStream(filePath, FileMode.Open, FileAccess.Read);
+            await using FileStream file = new(filePath, FileMode.Open, FileAccess.Read);
 
-            DiscordMessageBuilder directMessage = new DiscordMessageBuilder();
+            DiscordMessageBuilder directMessage = new();
 
-            if (zipSize >= 26214400)
+            if (zipTooLarge)
             {
                 directMessage.AddEmbed(new DiscordEmbedBuilder
                 {
@@ -176,7 +168,12 @@ public class TranscriptCommand
             directMessage.AddFiles(new Dictionary<string, Stream> { { fileName, file } });
 
             await command.Member.SendMessageAsync(directMessage);
-            return true;
+
+            await command.EditResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
+            {
+                Color = DiscordColor.Green,
+                Description = "Transcript sent!\n"
+            }));
         }
         catch (UnauthorizedException)
         {
@@ -185,7 +182,6 @@ public class TranscriptCommand
                 Color = DiscordColor.Red,
                 Description = "Not allowed to send direct message to you, please check your privacy settings.\n"
             }));
-            return false;
         }
     }
 }
\ No newline at end of file