From b992d20da79b9de020d629bf9574abefff9c4b12 Mon Sep 17 00:00:00 2001 From: Rory& Date: Wed, 20 Mar 2024 12:00:54 +0100 Subject: New messagebuilder stuff, table-based help command --- LibMatrix/Helpers/MessageBuilder.cs | 37 ++++++++++++++++++++++++++++++++----- LibMatrix/Helpers/SyncHelper.cs | 2 -- 2 files changed, 32 insertions(+), 7 deletions(-) (limited to 'LibMatrix/Helpers') diff --git a/LibMatrix/Helpers/MessageBuilder.cs b/LibMatrix/Helpers/MessageBuilder.cs index 0753aca..d897078 100644 --- a/LibMatrix/Helpers/MessageBuilder.cs +++ b/LibMatrix/Helpers/MessageBuilder.cs @@ -1,4 +1,3 @@ -using ArcaneLibs; using LibMatrix.EventTypes.Spec; namespace LibMatrix.Helpers; @@ -50,7 +49,7 @@ public class MessageBuilder(string msgType = "m.text", string format = "org.matr Content.FormattedBody += ""; return this; } - + public MessageBuilder WithCustomEmoji(string mxcUri, string name) { Content.Body += $"{{{name}}}"; Content.FormattedBody += $"\"{name}\""; @@ -72,23 +71,51 @@ public class MessageBuilder(string msgType = "m.text", string format = "org.matr // } return this; } - + public MessageBuilder WithCodeBlock(string code, string language = "plaintext") { Content.Body += code; Content.FormattedBody += $"
{code}
"; return this; } - + public MessageBuilder WithCollapsibleSection(string title, string body) { Content.Body += body; Content.FormattedBody += $"
{title}{body}
"; return this; } - + public MessageBuilder WithCollapsibleSection(string title, Action bodyBuilder) { Content.FormattedBody += $"
{title}"; bodyBuilder(this); Content.FormattedBody += "
"; return this; } + + public MessageBuilder WithTable(Action tableBuilder) { + var tb = new TableBuilder(this); + this.WithHtmlTag("table", msb => tableBuilder(tb)); + return this; + } + + public class TableBuilder(MessageBuilder msb) { + public TableBuilder WithTitle(string title, int colspan) { + msb.Content.Body += title + "\n"; + msb.Content.FormattedBody += $"{title}"; + return this; + } + + public TableBuilder WithRow(Action rowBuilder) { + var rb = new RowBuilder(msb); + msb.WithHtmlTag("tr", msb => rowBuilder(rb)).WithBody("\n"); + return this; + } + + public class RowBuilder(MessageBuilder msb) { + public RowBuilder WithCell(string content, Dictionary? attributes = null) { + msb.Content.Body += content + "\n"; + msb.Content.FormattedBody += $"{content}\t"; + return this; + } + } + } } \ No newline at end of file diff --git a/LibMatrix/Helpers/SyncHelper.cs b/LibMatrix/Helpers/SyncHelper.cs index e696b70..1833bd0 100644 --- a/LibMatrix/Helpers/SyncHelper.cs +++ b/LibMatrix/Helpers/SyncHelper.cs @@ -1,7 +1,5 @@ using System.Diagnostics; using System.Net.Http.Json; -using System.Text.Json; -using System.Text.Json.Serialization; using ArcaneLibs.Extensions; using LibMatrix.Filters; using LibMatrix.Homeservers; -- cgit 1.4.1