diff --git a/src/NadekoBot/Modules/Searches/Commands/UnitConversion.cs b/src/NadekoBot/Modules/Searches/Commands/UnitConversion.cs index b13c97e7..64422620 100644 --- a/src/NadekoBot/Modules/Searches/Commands/UnitConversion.cs +++ b/src/NadekoBot/Modules/Searches/Commands/UnitConversion.cs @@ -113,7 +113,7 @@ namespace NadekoBot.Modules.Searches } sb.AppendLine("```"); } - await msg.ReplyLong(sb.ToString(),addToPartialStart : "```xl\n",addToPartialEnd: "```", breakOn: new[] { "```xl\n", "\n" }); + await msg.ReplyLong(sb.ToString(), breakOn: new[] { "```xl", "\n" }); } [LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias] [RequireContext(ContextType.Guild)] @@ -127,7 +127,7 @@ namespace NadekoBot.Modules.Searches sb.AppendLine(string.Join(",", group.Select(x => x.Triggers.FirstOrDefault()).OrderBy(x => x))); sb.AppendLine("```"); } - await msg.ReplyLong(sb.ToString(), addToPartialStart: "```xl\n", addToPartialEnd: "```", breakOn: new[] { "```xl\n", "\n" }); + await msg.ReplyLong(sb.ToString(), breakOn: new[] { "```xl\n", "\n" }); } [LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias] public async Task Convert(IUserMessage msg, string origin, string target, decimal value) diff --git a/src/NadekoBot/_Extensions/Extensions.cs b/src/NadekoBot/_Extensions/Extensions.cs index feb9dcaf..e0d37a55 100644 --- a/src/NadekoBot/_Extensions/Extensions.cs +++ b/src/NadekoBot/_Extensions/Extensions.cs @@ -32,7 +32,7 @@ namespace NadekoBot.Extensions public static async Task SendFileAsync(this IGuildUser user, Stream fileStream, string fileName, string caption = null, bool isTTS = false) => await (await user.CreateDMChannelAsync().ConfigureAwait(false)).SendFileAsync(fileStream, fileName, caption, isTTS).ConfigureAwait(false); - + public static async Task Reply(this IUserMessage msg, string content) => await msg.Channel.SendMessageAsync(content).ConfigureAwait(false); @@ -41,7 +41,7 @@ namespace NadekoBot.Extensions public static IEnumerable Members(this IRole role) => NadekoBot.Client.GetGuild(role.GuildId)?.GetUsers().Where(u => u.Roles.Contains(role)) ?? Enumerable.Empty(); - + public static async Task ReplyLong(this IUserMessage msg, string content, string[] breakOn = null, string addToPartialEnd = "", string addToPartialStart = "") { if (content.Length == 0) return null; @@ -54,17 +54,16 @@ namespace NadekoBot.Extensions { if (splitItems.Count == 0) { - splitItems = content.Split(new[] { breaker }, StringSplitOptions.RemoveEmptyEntries).Select(x => x += breaker).ToList(); + splitItems = Regex.Split(content, $"(?={breaker})").Where(s => !string.IsNullOrWhiteSpace(s)).ToList(); } else { for (int i = 0; i < splitItems.Count; i++) { - var temp = splitItems[i]; if (temp.Length > characterLimit) { - var splitDeep = temp.Split(new[] { breaker }, StringSplitOptions.RemoveEmptyEntries).Select(x => x += breaker); + var splitDeep = Regex.Split(temp, $"(?={breaker})").Where(s => !string.IsNullOrWhiteSpace(s)); splitItems.RemoveAt(i); splitItems.InsertRange(i, splitDeep); } @@ -78,12 +77,12 @@ namespace NadekoBot.Extensions splitItems = splitItems.Where(s => s.Length < characterLimit).ToList(); } //ensured every item can be sent (if individually) - var firstItem = true; - Queue buildItems = new Queue(); + var firstItem = true; + Queue buildItems = new Queue(splitItems); StringBuilder builder = new StringBuilder(); - + while (buildItems.Count > 0) - { + { if (builder.Length == 0) { //first item to add @@ -92,7 +91,8 @@ namespace NadekoBot.Extensions else firstItem = false; builder.Append(buildItems.Dequeue()); - } else + } + else { builder.Append(buildItems.Dequeue()); } @@ -100,7 +100,8 @@ namespace NadekoBot.Extensions { list.Add(await msg.Channel.SendMessageAsync(builder.ToString())); builder.Clear(); - } else + } + else { var peeked = buildItems.Peek(); if (builder.Length + peeked.Length + addToPartialEnd.Length > characterLimit)