From 71d115dc8e915a620dd935955ba980fcbe421dad Mon Sep 17 00:00:00 2001 From: "Emma [it/its]@Rory&" Date: Fri, 1 Dec 2023 12:16:00 +0100 Subject: Cleanup, move ArcaneLibs to submodule instead of parent submodule --- ExampleBots/ModerationBot/PolicyEngine.cs | 34 +++++++++++++++---------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'ExampleBots/ModerationBot/PolicyEngine.cs') diff --git a/ExampleBots/ModerationBot/PolicyEngine.cs b/ExampleBots/ModerationBot/PolicyEngine.cs index 5311637..8bfa448 100644 --- a/ExampleBots/ModerationBot/PolicyEngine.cs +++ b/ExampleBots/ModerationBot/PolicyEngine.cs @@ -11,9 +11,9 @@ using LibMatrix.Homeservers; using LibMatrix.Interfaces; using LibMatrix.RoomTypes; using LibMatrix.Services; +using Microsoft.Extensions.Logging; using ModerationBot.AccountData; using ModerationBot.StateEventTypes; -using Microsoft.Extensions.Logging; using ModerationBot.StateEventTypes.Policies; using ModerationBot.StateEventTypes.Policies.Implementations; @@ -67,7 +67,7 @@ public class PolicyEngine(AuthenticatedHomeserverGeneric hs, ILogger x.Policies.Count)} policies total, {sw.Elapsed} elapsed.") .SetReplaceRelation(progressMessage.EventId); - + _logRoom?.SendMessageEventAsync(progressMsgContent); } } @@ -99,8 +99,8 @@ public class PolicyEngine(AuthenticatedHomeserverGeneric hs, ILogger x.Room.RoomId == roomId)) return; await LoadPolicyListAsync(hs.GetRoom(roomId), ActivePolicyLists.Single(x => x.Room.RoomId == roomId)); @@ -140,7 +140,7 @@ public class PolicyEngine(AuthenticatedHomeserverGeneric hs, ILogger> GetMatchingPolicies(StateEventResponse @event) { List matchingPolicies = new(); if (@event.Sender == @hs.UserId) return matchingPolicies; //ignore self at all costs - + if (ActivePoliciesByType.TryGetValue(nameof(ServerPolicyRuleEventContent), out var serverPolicies)) { var userServer = @event.Sender.Split(':', 2)[1]; matchingPolicies.AddRange(serverPolicies.Where(x => x.Entity == userServer)); @@ -160,19 +160,19 @@ public class PolicyEngine(AuthenticatedHomeserverGeneric hs, ILogger> CheckMessageContent(StateEventResponse @event) { var matchedRules = new List(); var msgContent = @event.TypedContent as RoomMessageEventContent; - + if (ActivePoliciesByType.TryGetValue(nameof(MessagePolicyContainsText), out var messageContainsPolicies)) foreach (var policy in messageContainsPolicies) { - if((@msgContent?.Body?.ToLowerInvariant().Contains(policy.Entity.ToLowerInvariant()) ?? false) || (@msgContent?.FormattedBody?.ToLowerInvariant().Contains(policy.Entity.ToLowerInvariant()) ?? false)) + if ((@msgContent?.Body?.ToLowerInvariant().Contains(policy.Entity.ToLowerInvariant()) ?? false) || (@msgContent?.FormattedBody?.ToLowerInvariant().Contains(policy.Entity.ToLowerInvariant()) ?? false)) matchedRules.Add(policy); } - - + + return matchedRules; } @@ -238,17 +238,17 @@ public class PolicyEngine(AuthenticatedHomeserverGeneric hs, ILogger states) { string raw = "Count | State type | Mapped type", html = ""; @@ -262,8 +262,8 @@ public class PolicyEngine(AuthenticatedHomeserverGeneric hs, ILogger
CountState typeMapped type