about summary refs log tree commit diff
path: root/ExampleBots/ModerationBot
diff options
context:
space:
mode:
authorEmma [it/its]@Rory& <root@rory.gay>2024-01-05 12:22:42 +0100
committerEmma [it/its]@Rory& <root@rory.gay>2024-01-05 12:22:42 +0100
commitf215dca816745ef54f5436d6cea9350d6dcd3982 (patch)
tree2749bcd4d1297943478b6080d5688ef642ca1d40 /ExampleBots/ModerationBot
parentToObject and ToJson for MatrixException (diff)
downloadLibMatrix-f215dca816745ef54f5436d6cea9350d6dcd3982.tar.xz
Cleanup
Diffstat (limited to 'ExampleBots/ModerationBot')
-rw-r--r--ExampleBots/ModerationBot/Commands/DbgDumpAllStateTypesCommand.cs4
-rw-r--r--ExampleBots/ModerationBot/ModerationBot.cs6
-rw-r--r--ExampleBots/ModerationBot/PolicyEngine.cs8
3 files changed, 9 insertions, 9 deletions
diff --git a/ExampleBots/ModerationBot/Commands/DbgDumpAllStateTypesCommand.cs b/ExampleBots/ModerationBot/Commands/DbgDumpAllStateTypesCommand.cs
index 3727877..7563cac 100644
--- a/ExampleBots/ModerationBot/Commands/DbgDumpAllStateTypesCommand.cs
+++ b/ExampleBots/ModerationBot/Commands/DbgDumpAllStateTypesCommand.cs
@@ -59,8 +59,8 @@ public class DbgDumpAllStateTypesCommand
         string raw = "Count | State type | Mapped type", html = "<table><tr><th>Count</th><th>State type</th><th>Mapped type</th></tr>";
         var groupedStates = states.GroupBy(x => x.Type).ToDictionary(x => x.Key, x => x.ToList()).OrderByDescending(x => x.Value.Count);
         foreach (var (type, stateGroup) in groupedStates) {
-            raw += $"{stateGroup.Count} | {type} | {stateGroup[0].GetType.Name}";
-            html += $"<tr><td>{stateGroup.Count}</td><td>{type}</td><td>{stateGroup[0].GetType.Name}</td></tr>";
+            raw += $"{stateGroup.Count} | {type} | {StateEvent.GetStateEventType(stateGroup[0].Type).Name}";
+            html += $"<tr><td>{stateGroup.Count}</td><td>{type}</td><td>{StateEvent.GetStateEventType(stateGroup[0].Type).Name}</td></tr>";
         }
 
         html += "</table>";
diff --git a/ExampleBots/ModerationBot/ModerationBot.cs b/ExampleBots/ModerationBot/ModerationBot.cs
index 1be7bd5..7c95229 100644
--- a/ExampleBots/ModerationBot/ModerationBot.cs
+++ b/ExampleBots/ModerationBot/ModerationBot.cs
@@ -70,7 +70,7 @@ public class ModerationBot(AuthenticatedHomeserverGeneric hs, ILogger<Moderation
 #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
         Task.Run(async () => {
             while (!cancellationToken.IsCancellationRequested) {
-                var controlRoomMembers = _controlRoom.GetMembersAsync();
+                var controlRoomMembers = _controlRoom.GetMembersEnumerableAsync();
                 var pls = await _controlRoom.GetPowerLevelsAsync();
                 await foreach (var member in controlRoomMembers) {
                     if ((member.TypedContent as RoomMemberEventContent)?
@@ -110,8 +110,8 @@ public class ModerationBot(AuthenticatedHomeserverGeneric hs, ILogger<Moderation
                     "Got timeline event in {}: {}", @event.RoomId, @event.ToJson(indent: true, ignoreNull: true));
 
                 if (@event != null && (
-                        @event.GetType.IsAssignableTo(typeof(BasePolicy))
-                        || @event.GetType.IsAssignableTo(typeof(PolicyRuleEventContent))
+                        @event.MappedType.IsAssignableTo(typeof(BasePolicy))
+                        || @event.MappedType.IsAssignableTo(typeof(PolicyRuleEventContent))
                     ))
                     await engine.ReloadActivePolicyListById(@event.RoomId);
 
diff --git a/ExampleBots/ModerationBot/PolicyEngine.cs b/ExampleBots/ModerationBot/PolicyEngine.cs
index 5af99ac..114b90d 100644
--- a/ExampleBots/ModerationBot/PolicyEngine.cs
+++ b/ExampleBots/ModerationBot/PolicyEngine.cs
@@ -85,8 +85,8 @@ public class PolicyEngine(AuthenticatedHomeserverGeneric hs, ILogger<ModerationB
         var stateEvents = room.GetFullStateAsync();
         await foreach (var stateEvent in stateEvents) {
             if (stateEvent != null && (
-                    stateEvent.GetType.IsAssignableTo(typeof(BasePolicy))
-                    || stateEvent.GetType.IsAssignableTo(typeof(PolicyRuleEventContent))
+                    stateEvent.MappedType.IsAssignableTo(typeof(BasePolicy))
+                    || stateEvent.MappedType.IsAssignableTo(typeof(PolicyRuleEventContent))
                 )) {
                 policyList.Policies.Add(stateEvent);
             }
@@ -253,8 +253,8 @@ public class PolicyEngine(AuthenticatedHomeserverGeneric hs, ILogger<ModerationB
         string raw = "Count | State type | Mapped type", html = "<table><tr><th>Count</th><th>State type</th><th>Mapped type</th></tr>";
         var groupedStates = states.GroupBy(x => x.Type).ToDictionary(x => x.Key, x => x.ToList()).OrderByDescending(x => x.Value.Count);
         foreach (var (type, stateGroup) in groupedStates) {
-            raw += $"{stateGroup.Count} | {type} | {stateGroup[0].GetType.Name}";
-            html += $"<tr><td>{stateGroup.Count}</td><td>{type}</td><td>{stateGroup[0].GetType.Name}</td></tr>";
+            raw += $"{stateGroup.Count} | {type} | {stateGroup[0].MappedType.Name}";
+            html += $"<tr><td>{stateGroup.Count}</td><td>{type}</td><td>{stateGroup[0].MappedType.Name}</td></tr>";
         }
 
         html += "</table>";