feat: implement link embed functionality to enhance message previews with metadata and thumbnails

This commit is contained in:
HueByte
2026-02-19 21:21:51 +01:00
parent 6965ba573e
commit 7167b40013
18 changed files with 740 additions and 15 deletions
@@ -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.