From 5eb2ef62b913773fb7b801cf4f36c5561192a7e6 Mon Sep 17 00:00:00 2001 From: barelyprofessional <150058423+barelyprofessional@users.noreply.github.com> Date: Sun, 9 Feb 2025 23:34:48 +0800 Subject: [PATCH] Added support for custom part separators when using the fancy split message extension method --- KfChatDotNetBot/Commands/AdminCommands.cs | 4 ++-- KfChatDotNetBot/Extensions.cs | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/KfChatDotNetBot/Commands/AdminCommands.cs b/KfChatDotNetBot/Commands/AdminCommands.cs index daae646..5ea9b9e 100644 --- a/KfChatDotNetBot/Commands/AdminCommands.cs +++ b/KfChatDotNetBot/Commands/AdminCommands.cs @@ -123,7 +123,7 @@ public class GmKasinoListCommand : ICommand result += $"[br]{i}: {image}"; } - await botInstance.SendChatMessagesAsync(result.FancySplitMessage(), true); + await botInstance.SendChatMessagesAsync(result.FancySplitMessage(partSeparator: "[br]"), true); } } @@ -213,7 +213,7 @@ public class GnKasinoListCommand : ICommand result += $"[br]{i}: {image}"; } - await botInstance.SendChatMessagesAsync(result.FancySplitMessage(), true); + await botInstance.SendChatMessagesAsync(result.FancySplitMessage(partSeparator: "[br]"), true); } } diff --git a/KfChatDotNetBot/Extensions.cs b/KfChatDotNetBot/Extensions.cs index e3e7e22..ae0a78c 100644 --- a/KfChatDotNetBot/Extensions.cs +++ b/KfChatDotNetBot/Extensions.cs @@ -51,12 +51,13 @@ public static class Extensions /// String that should get split /// Length limit, no part should be > than the number of bytes specified /// Limit for how many parts to return (returns first n elements). Set to 0 to disable. - /// - public static List FancySplitMessage(this string s, int partLengthBytes = 1023, int partLimit = 5) + /// Separator to use when splitting up parts of the message + /// List of string values which represents the split up message + public static List FancySplitMessage(this string s, int partLengthBytes = 1023, int partLimit = 5, string partSeparator = " ") { var output = new List(); var part = string.Empty; - foreach (var word in s.Split(' ')) + foreach (var word in s.Split(partSeparator)) { if (word.Utf8LengthBytes() > partLengthBytes) { @@ -75,11 +76,11 @@ public static class Extensions { // TrimEnd() to remove trailing spaces output.Add(part.TrimEnd()); - part = word + " "; + part = word + partSeparator; continue; } - part += word + " "; + part += word + partSeparator; } // Add on whatever remains