about summary refs log tree commit diff
path: root/LibMatrix/Helpers
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2024-03-15 18:10:58 +0100
committerRory& <root@rory.gay>2024-03-15 18:11:18 +0100
commit096375344ef87fe53ca009b7a7eaa34c9c9f5407 (patch)
tree76d666cd6961ca04ae9e91e47c43d91eed27a87a /LibMatrix/Helpers
parentFix README (diff)
downloadLibMatrix-096375344ef87fe53ca009b7a7eaa34c9c9f5407.tar.xz
Bot changes, move named filters to subclass
Diffstat (limited to 'LibMatrix/Helpers')
-rw-r--r--LibMatrix/Helpers/MessageBuilder.cs24
-rw-r--r--LibMatrix/Helpers/SyncHelper.cs2
2 files changed, 20 insertions, 6 deletions
diff --git a/LibMatrix/Helpers/MessageBuilder.cs b/LibMatrix/Helpers/MessageBuilder.cs
index 68f6300..07953e3 100644
--- a/LibMatrix/Helpers/MessageBuilder.cs
+++ b/LibMatrix/Helpers/MessageBuilder.cs
@@ -50,11 +50,18 @@ 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}\" />";
+        return this;
+    }
+
+    public MessageBuilder WithRainbowString(string text, byte skip = 1, int offset = 0, double lengthFactor = 255.0, bool useLength = true) {
+        if (useLength) {
+            lengthFactor = text.Length;
+        }
 
-    public MessageBuilder WithRainbowString(string text, byte skip = 1, int offset = 0, double lengthFactor = 255.0, bool useLength = true) =>
-        // if (useLength) {
-        //     lengthFactor = text.Length;
-        // }
         // HslaColorInterpolator interpolator = new((0, 255, 128, 255), (255, 255, 128, 255));
         // // RainbowEnumerator enumerator = new(skip, offset, lengthFactor);
         // for (int i = 0; i < text.Length; i++) {
@@ -63,5 +70,12 @@ public class MessageBuilder(string msgType = "m.text", string format = "org.matr
         //     // Console.WriteLine($"RBA: {r} {g} {b} {a}");
         //     // Content.FormattedBody += $"<font color=\"#{r:X2}{g:X2}{b:X2}\">{text[i]}</font>";
         // }
-        this;
+        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;
+    }
 }
\ No newline at end of file
diff --git a/LibMatrix/Helpers/SyncHelper.cs b/LibMatrix/Helpers/SyncHelper.cs
index 9d339e4..e696b70 100644
--- a/LibMatrix/Helpers/SyncHelper.cs
+++ b/LibMatrix/Helpers/SyncHelper.cs
@@ -55,7 +55,7 @@ public class SyncHelper(AuthenticatedHomeserverGeneric homeserver, ILogger? logg
 
     private async Task updateFilterAsync() {
         if (!string.IsNullOrWhiteSpace(NamedFilterName)) {
-            _filterId = await homeserver.GetOrUploadNamedFilterIdAsync(NamedFilterName);
+            _filterId = await homeserver.NamedCaches.FilterCache.GetOrSetValueAsync(NamedFilterName);
             if (_filterId is null)
                 if (logger is null) Console.WriteLine($"Failed to get filter ID for named filter {NamedFilterName}");
                 else logger.LogWarning("Failed to get filter ID for named filter {NamedFilterName}", NamedFilterName);