mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2026-08-29 13:04:59 +00:00
Add chat formatting code propagation (bold, italic, underline, strikethrough, obfuscated)
Re-implements PR #2851 against the current System.Text.Json.Nodes codebase. Changes: - ChatParser.cs: Add FormattingCodes dict, update JSONData2String to propagate formatting codes alongside colors, update NbtToString for the NBT chat path (used in MC 1.20.4+), fix root-string shortcut to preserve formatting prefix - DiscordBridge.cs: Add GetDiscordText() converting § codes to Discord Markdown, handle unclosed formatting codes with end-of-string matching End-to-end tested against Minecraft 1.21.11 (MC 26.1) offline server. All 8 formatting types verified: bold(§l), italic(§o), strikethrough(§m), underline(§n), combined, nested, reset-via-false, obfuscated(§k). Co-authored-by: milutinke <441903+milutinke@users.noreply.github.com> Agent-Logs-Url: https://github.com/MCCTeam/Minecraft-Console-Client/sessions/65b0d230-287c-4ed8-9b3c-a5ea25411804
This commit is contained in:
parent
16a3ad2b69
commit
3fb7625b39
2 changed files with 123 additions and 78 deletions
|
|
@ -2,6 +2,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using Brigadier.NET.Builder;
|
||||
using DSharpPlus;
|
||||
|
|
@ -222,7 +223,22 @@ namespace MinecraftClient.ChatBots
|
|||
SendMessage(messageBuilder);
|
||||
return;
|
||||
}
|
||||
else SendMessage(message);
|
||||
else SendMessage(GetDiscordText(message));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts Minecraft § formatting codes to Discord Markdown equivalents
|
||||
/// and strips remaining § codes.
|
||||
/// Handles both properly closed formatting (§l...§r) and unclosed formatting (§l... end).
|
||||
/// </summary>
|
||||
private static string GetDiscordText(string text)
|
||||
{
|
||||
text = Regex.Replace(text, @"§l(.*?)(?:§r|$)", "**$1**");
|
||||
text = Regex.Replace(text, @"§m(.*?)(?:§r|$)", "~~$1~~");
|
||||
text = Regex.Replace(text, @"§n(.*?)(?:§r|$)", "__$1__");
|
||||
text = Regex.Replace(text, @"§o(.*?)(?:§r|$)", "*$1*");
|
||||
text = Regex.Replace(text, @"§.", "");
|
||||
return text;
|
||||
}
|
||||
|
||||
public void SendMessage(string message)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue