mirror of
https://github.com/RedWizardsLab/EchoHub.git
synced 2026-09-04 08:36:11 +02:00
feat: implement link embed functionality to enhance message previews with metadata and thumbnails
This commit is contained in:
@@ -23,6 +23,10 @@ public static partial class IrcMessageFormatter
|
||||
case MessageType.Text:
|
||||
foreach (var chunk in SplitMessage(message.Content, MaxIrcLineContentBytes))
|
||||
lines.Add($"{prefix} PRIVMSG {ircChannel} :{chunk}");
|
||||
|
||||
// Append embed preview if present
|
||||
if (message.Embed is not null)
|
||||
lines.AddRange(FormatEmbed(prefix, ircChannel, message.Embed));
|
||||
break;
|
||||
|
||||
case MessageType.Image:
|
||||
@@ -46,6 +50,33 @@ public static partial class IrcMessageFormatter
|
||||
return lines;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Format a link embed as IRC PRIVMSG lines (text-only, no ASCII thumbnail).
|
||||
/// </summary>
|
||||
private static List<string> FormatEmbed(string prefix, string ircChannel, EmbedDto embed)
|
||||
{
|
||||
var lines = new List<string>();
|
||||
|
||||
var header = new List<string>();
|
||||
if (!string.IsNullOrWhiteSpace(embed.SiteName))
|
||||
header.Add(embed.SiteName);
|
||||
if (!string.IsNullOrWhiteSpace(embed.Title))
|
||||
header.Add(embed.Title);
|
||||
|
||||
if (header.Count > 0)
|
||||
lines.Add($"{prefix} PRIVMSG {ircChannel} :\u2502 {string.Join(" \u2014 ", header)}");
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(embed.Description))
|
||||
{
|
||||
var desc = embed.Description.Length > 200
|
||||
? embed.Description[..197] + "..."
|
||||
: embed.Description;
|
||||
lines.Add($"{prefix} PRIVMSG {ircChannel} :\u2502 {desc}");
|
||||
}
|
||||
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user