mirror of
https://github.com/RedWizardsLab/EchoHub.git
synced 2026-09-06 07:36:01 +02:00
feat: add IsPublic property to channels and enhance channel creation with visibility options
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using EchoHub.Core.DTOs;
|
||||
using EchoHub.Core.Models;
|
||||
|
||||
namespace EchoHub.Server.Irc;
|
||||
|
||||
public static class IrcMessageFormatter
|
||||
public static partial class IrcMessageFormatter
|
||||
{
|
||||
private const int MaxIrcLineContentBytes = 400;
|
||||
|
||||
@@ -33,7 +34,7 @@ public static class IrcMessageFormatter
|
||||
{
|
||||
var trimmed = line.TrimEnd('\r');
|
||||
if (trimmed.Length > 0)
|
||||
lines.Add($"{prefix} PRIVMSG {ircChannel} :{trimmed}");
|
||||
lines.Add($"{prefix} PRIVMSG {ircChannel} :{ColorTagsToAnsi(trimmed)}");
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -45,6 +46,35 @@ public static class IrcMessageFormatter
|
||||
return lines;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert printable color tags ({F:RRGGBB}, {B:RRGGBB}, {X}) to ANSI escape codes for IRC clients.
|
||||
/// Also passes through content that already uses ANSI codes unchanged.
|
||||
/// </summary>
|
||||
public static string ColorTagsToAnsi(string text)
|
||||
{
|
||||
if (!text.Contains('{'))
|
||||
return text;
|
||||
|
||||
return ColorTagRegex().Replace(text, match =>
|
||||
{
|
||||
if (match.Groups[1].Success) // {X} reset
|
||||
return "\x1b[0m";
|
||||
if (match.Groups[2].Success) // {F:RRGGBB} or {B:RRGGBB}
|
||||
{
|
||||
var hex = match.Groups[3].Value;
|
||||
var r = Convert.ToInt32(hex[..2], 16);
|
||||
var g = Convert.ToInt32(hex[2..4], 16);
|
||||
var b = Convert.ToInt32(hex[4..6], 16);
|
||||
var code = match.Groups[2].Value == "F" ? "38" : "48";
|
||||
return $"\x1b[{code};2;{r};{g};{b}m";
|
||||
}
|
||||
return match.Value;
|
||||
});
|
||||
}
|
||||
|
||||
[GeneratedRegex(@"\{(?:(X)|(?:(F|B):([0-9A-Fa-f]{6})))\}")]
|
||||
private static partial Regex ColorTagRegex();
|
||||
|
||||
/// <summary>
|
||||
/// Split a message into chunks of approximately maxBytes (UTF-8), at word boundaries.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user