From aa01314b3a8abcfaab62f16d7e7b12e798185d08 Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Sat, 8 Jul 2017 14:20:06 +0200 Subject: [PATCH] Embed field names and values will be trimmed to their acceptable length to prevent errors. closes #1355 --- src/NadekoBot/DataStructures/CREmbed.cs | 9 ++++++++- src/NadekoBot/Modules/CustomReactions/CustomReactions.cs | 2 +- src/NadekoBot/Modules/Searches/Commands/LoLCommands.cs | 2 +- src/NadekoBot/_strings/ResponseStrings.en-US.json | 1 + 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/NadekoBot/DataStructures/CREmbed.cs b/src/NadekoBot/DataStructures/CREmbed.cs index 14426310..4fdf78e3 100644 --- a/src/NadekoBot/DataStructures/CREmbed.cs +++ b/src/NadekoBot/DataStructures/CREmbed.cs @@ -1,4 +1,5 @@ using Discord; +using NadekoBot.Extensions; using Newtonsoft.Json; using NLog; using System; @@ -71,7 +72,13 @@ namespace NadekoBot.DataStructures try { var crembed = JsonConvert.DeserializeObject(input); - + + if(crembed.Fields != null && crembed.Fields.Length > 0) + foreach (var f in crembed.Fields) + { + f.Name = f.Name.TrimTo(256); + f.Value = f.Value.TrimTo(1024); + } if (!crembed.IsValid) return false; diff --git a/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs b/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs index ae033cad..dd6b162d 100644 --- a/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs +++ b/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs @@ -79,7 +79,7 @@ namespace NadekoBot.Modules.CustomReactions .WithTitle(GetText("new_cust_react")) .WithDescription($"#{cr.Id}") .AddField(efb => efb.WithName(GetText("trigger")).WithValue(key)) - .AddField(efb => efb.WithName(GetText("response")).WithValue(message)) + .AddField(efb => efb.WithName(GetText("response")).WithValue(message.Length > 1024 ? GetText("redacted_too_long") : message)) ).ConfigureAwait(false); } diff --git a/src/NadekoBot/Modules/Searches/Commands/LoLCommands.cs b/src/NadekoBot/Modules/Searches/Commands/LoLCommands.cs index bf15651b..91282423 100644 --- a/src/NadekoBot/Modules/Searches/Commands/LoLCommands.cs +++ b/src/NadekoBot/Modules/Searches/Commands/LoLCommands.cs @@ -33,7 +33,7 @@ namespace NadekoBot.Modules.Searches [NadekoCommand, Usage, Description, Aliases] public async Task Lolban() { - const int showCount = 8; + //const int showCount = 8; //http://api.champion.gg/stats/champs/mostBanned?api_key=YOUR_API_TOKEN&page=1&limit=2 try { diff --git a/src/NadekoBot/_strings/ResponseStrings.en-US.json b/src/NadekoBot/_strings/ResponseStrings.en-US.json index 06d62f39..7c330d6d 100644 --- a/src/NadekoBot/_strings/ResponseStrings.en-US.json +++ b/src/NadekoBot/_strings/ResponseStrings.en-US.json @@ -35,6 +35,7 @@ "customreactions_stats_cleared": "Stats cleared for {0} custom reaction.", "customreactions_stats_not_found": "No stats for that trigger found, no action taken.", "customreactions_trigger": "Trigger", + "customreactions_redacted_too_long": "Redecated because it's too long.", "nsfw_autohentai_stopped": "Autohentai stopped.", "nsfw_not_found": "No results found.", "pokemon_already_fainted": "{0} has already fainted.",