Implement failsafe for large message output from custom commands
This commit is contained in:
parent
fe5dde6918
commit
838c4847f8
@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ChaosBot.Models;
|
||||
@ -39,8 +41,17 @@ namespace ChaosBot.Services.ProgrammingLanguageInterpreter
|
||||
}
|
||||
|
||||
string output = task.Result;
|
||||
|
||||
if (output.Length > 0)
|
||||
|
||||
if (output.Length > 2000)
|
||||
{
|
||||
context.Channel.SendMessageAsync($"Command '{customCommand.Command}' has {output.Length} characters of output. That is more than the 2000 limit. Packaging into file...").GetAwaiter().GetResult();
|
||||
Stream stream = new MemoryStream(Encoding.ASCII.GetBytes(output));
|
||||
if (stream.Length > 8 * 1024 * 1024)
|
||||
context.Channel.SendMessageAsync($"Packaged filesize of {stream.Length / 1024 / 1024} MB is too big.");
|
||||
else
|
||||
context.Channel.SendFileAsync(stream, "command-output.txt");
|
||||
}
|
||||
else if (output.Length > 0)
|
||||
context.Channel.SendMessageAsync(output);
|
||||
else
|
||||
context.Channel.SendMessageAsync($"Command '{customCommand.Command}' had no output.");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user