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