parent
df2f2e63c9
commit
63276257d2
1 changed files with 19 additions and 23 deletions
|
@ -83,18 +83,22 @@ public class TranscriptCommand
|
||||||
|
|
||||||
string fileName = Transcriber.GetZipFilename(ticket.id);
|
string fileName = Transcriber.GetZipFilename(ticket.id);
|
||||||
string filePath = Transcriber.GetZipPath(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
|
try
|
||||||
{
|
{
|
||||||
FileInfo fileInfo = new FileInfo(filePath);
|
FileInfo zipFile = new(filePath);
|
||||||
if (!fileInfo.Exists || fileInfo.Length >= 26214400)
|
if (!zipFile.Exists || zipFile.Length >= 26214400)
|
||||||
{
|
{
|
||||||
fileName = Transcriber.GetHTMLFilename(ticket.id);
|
fileName = Transcriber.GetHTMLFilename(ticket.id);
|
||||||
filePath = Transcriber.GetHtmlPath(ticket.id);
|
filePath = Transcriber.GetHtmlPath(ticket.id);
|
||||||
}
|
}
|
||||||
zipSize = fileInfo.Length;
|
|
||||||
|
if (zipFile.Exists && zipFile.Length >= 26214400)
|
||||||
|
{
|
||||||
|
zipTooLarge = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -121,7 +125,7 @@ public class TranscriptCommand
|
||||||
|
|
||||||
try
|
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));
|
await LogChannel.Success("Transcript generated by " + command.User.Mention + ".", ticket.id, new Utilities.File(fileName, file));
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
@ -129,26 +133,14 @@ public class TranscriptCommand
|
||||||
Logger.Error("Failed to log transcript generation.", 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
|
try
|
||||||
{
|
{
|
||||||
// Send transcript in a direct message
|
// 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
|
directMessage.AddEmbed(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
|
@ -176,7 +168,12 @@ public class TranscriptCommand
|
||||||
directMessage.AddFiles(new Dictionary<string, Stream> { { fileName, file } });
|
directMessage.AddFiles(new Dictionary<string, Stream> { { fileName, file } });
|
||||||
|
|
||||||
await command.Member.SendMessageAsync(directMessage);
|
await command.Member.SendMessageAsync(directMessage);
|
||||||
return true;
|
|
||||||
|
await command.EditResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
|
||||||
|
{
|
||||||
|
Color = DiscordColor.Green,
|
||||||
|
Description = "Transcript sent!\n"
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
catch (UnauthorizedException)
|
catch (UnauthorizedException)
|
||||||
{
|
{
|
||||||
|
@ -185,7 +182,6 @@ public class TranscriptCommand
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
Description = "Not allowed to send direct message to you, please check your privacy settings.\n"
|
Description = "Not allowed to send direct message to you, please check your privacy settings.\n"
|
||||||
}));
|
}));
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue