diff options
author | Rory& <root@rory.gay> | 2024-03-20 12:00:54 +0100 |
---|---|---|
committer | Rory& <root@rory.gay> | 2024-03-20 12:00:54 +0100 |
commit | b992d20da79b9de020d629bf9574abefff9c4b12 (patch) | |
tree | a5205343b6edbc8f627215efdd147d86a4a737c7 /LibMatrix/Helpers/MessageBuilder.cs | |
parent | Bot related fixes, image size (diff) | |
download | LibMatrix-b992d20da79b9de020d629bf9574abefff9c4b12.tar.xz |
New messagebuilder stuff, table-based help command
Diffstat (limited to 'LibMatrix/Helpers/MessageBuilder.cs')
-rw-r--r-- | LibMatrix/Helpers/MessageBuilder.cs | 37 |
1 files changed, 32 insertions, 5 deletions
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 += "</font>"; return this; } - + public MessageBuilder WithCustomEmoji(string mxcUri, string name) { Content.Body += $"{{{name}}}"; Content.FormattedBody += $"<img data-mx-emoticon height=\"32\" src=\"{mxcUri}\" alt=\"{name}\" title=\"{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 += $"<pre><code class=\"language-{language}\">{code}</code></pre>"; return this; } - + public MessageBuilder WithCollapsibleSection(string title, string body) { Content.Body += body; Content.FormattedBody += $"<details><summary>{title}</summary>{body}</details>"; return this; } - + public MessageBuilder WithCollapsibleSection(string title, Action<MessageBuilder> bodyBuilder) { Content.FormattedBody += $"<details><summary>{title}</summary>"; bodyBuilder(this); Content.FormattedBody += "</details>"; return this; } + + public MessageBuilder WithTable(Action<TableBuilder> 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 += $"<thead><tr><th colspan=\"{colspan}\">{title}</th></tr></thead>"; + return this; + } + + public TableBuilder WithRow(Action<RowBuilder> 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<string, string>? attributes = null) { + msb.Content.Body += content + "\n"; + msb.Content.FormattedBody += $"<td>{content}</td>\t"; + return this; + } + } + } } \ No newline at end of file |