From 1b5580b0acb6b06f842eabf3de1907f3f85d7c6d Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Sat, 7 Nov 2020 21:12:31 -0500 Subject: [PATCH] Fix large DreamMaker output blobs breaking embeds - Precheck the size of dreamMakerOutput before attempting to create the EmbedFieldBuilder --- .../Components/Chat/Providers/DiscordProvider.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Tgstation.Server.Host/Components/Chat/Providers/DiscordProvider.cs b/src/Tgstation.Server.Host/Components/Chat/Providers/DiscordProvider.cs index df097473ae..e82c35b9d5 100644 --- a/src/Tgstation.Server.Host/Components/Chat/Providers/DiscordProvider.cs +++ b/src/Tgstation.Server.Host/Components/Chat/Providers/DiscordProvider.cs @@ -474,12 +474,16 @@ namespace Tgstation.Server.Host.Components.Chat.Providers _ => throw new InvalidOperationException($"Invalid DiscordDMOutputDisplayType: {outputDisplayType}"), }; - if (showDMOutput && dreamMakerOutput != null) - builder.AddField(new EmbedFieldBuilder - { - Name = "DreamMaker Output", - Value = $"```{Environment.NewLine}{dreamMakerOutput}{Environment.NewLine}```" - }); + if (dreamMakerOutput != null) + { + showDMOutput = showDMOutput && dreamMakerOutput.Length < EmbedFieldBuilder.MaxFieldValueLength - (6 + Environment.NewLine.Length); + if (showDMOutput) + builder.AddField(new EmbedFieldBuilder + { + Name = "DreamMaker Output", + Value = $"```{Environment.NewLine}{dreamMakerOutput}{Environment.NewLine}```" + }); + } if (errorMessage != null) builder.AddField(new EmbedFieldBuilder