Skip to content

Commit

Permalink
Fixed transcript command not being able to send old html transcripts
Browse files Browse the repository at this point in the history
  • Loading branch information
KarlOfDuty committed Feb 5, 2025
1 parent f32a17c commit 5fc99b2
Showing 1 changed file with 19 additions and 23 deletions.
42 changes: 19 additions & 23 deletions Commands/TranscriptCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,22 @@ await command.EditResponseAsync(new DiscordWebhookBuilder().AddEmbed(new Discord

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)
{
Expand All @@ -121,34 +125,22 @@ await command.EditResponseAsync(new DiscordWebhookBuilder().AddEmbed(new Discord

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)
{
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
{
Expand Down Expand Up @@ -176,7 +168,12 @@ private static async Task<bool> SendDirectMessage(SlashCommandContext command, s
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)
{
Expand All @@ -185,7 +182,6 @@ await command.EditResponseAsync(new DiscordWebhookBuilder().AddEmbed(new Discord
Color = DiscordColor.Red,
Description = "Not allowed to send direct message to you, please check your privacy settings.\n"
}));
return false;
}
}
}

0 comments on commit 5fc99b2

Please sign in to comment.