From 96e553845f115a945124ad82e565792a640af1fd Mon Sep 17 00:00:00 2001 From: barelyprofessional <150058423+barelyprofessional@users.noreply.github.com> Date: Tue, 26 Mar 2024 13:38:33 +0800 Subject: [PATCH] Implemented bbcode translation for Kick emotes using an extension method and regex --- KfChatDotNetKickBot/Extensions.cs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 KfChatDotNetKickBot/Extensions.cs diff --git a/KfChatDotNetKickBot/Extensions.cs b/KfChatDotNetKickBot/Extensions.cs new file mode 100644 index 0000000..f3e8b15 --- /dev/null +++ b/KfChatDotNetKickBot/Extensions.cs @@ -0,0 +1,30 @@ +using System.Text.RegularExpressions; + +namespace KfChatDotNetKickBot; + +public static class Extensions +{ + /// Emotes are encoded like [emote:161238:russW] which translates to -> https://files.kick.com/emotes/161238/fullsize + public static string TranslateKickEmotes(this string s) + { + Regex regex = new Regex(@"\[(.+?):(\d+):(\S+)\]"); + var matches = regex.Matches(s); + if (matches.Count == 0) + { + return s; + } + + foreach (Match match in matches) + { + // First group is the whole matched string + // 0 -> [emote:161238:russW] + // 1 -> emote + // 2 -> 161238 + // 3 -> russW + var emoteId = match.Groups[2]; + s = s.Replace(match.Value, $"[img]https://files.kick.com/emotes/{emoteId}/fullsize[/img]"); + } + + return s; + } +} \ No newline at end of file