From 2fde2d5f961eabf3167280ba55786cdb6b38f2c0 Mon Sep 17 00:00:00 2001 From: Rory& Date: Fri, 2 May 2025 16:21:13 +0200 Subject: Add support for ignoring users, add user/room/event reporting --- .../Spec/State/Policy/PolicyRuleStateEventContent.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'LibMatrix.EventTypes/Spec/State') diff --git a/LibMatrix.EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs b/LibMatrix.EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs index 0cb4a25..6f8c194 100644 --- a/LibMatrix.EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs +++ b/LibMatrix.EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs @@ -97,16 +97,27 @@ public abstract class PolicyRuleEventContent : EventContent { public Regex? GetEntityRegex() => Entity is null ? null : new(Entity.Replace(".", "\\.").Replace("*", ".*").Replace("?", ".")); + public bool IsGlobRule() => + Entity != null + && (Entity.Contains('*') || Entity.Contains('?')); + public bool EntityMatches(string entity) => Entity != null && ( Entity == entity || ( - Entity.Contains("*") || Entity.Contains("?") + IsGlobRule() ? GetEntityRegex()!.IsMatch(entity) : entity == Entity ) ); + + public string? GetNormalizedRecommendation() { + if (Recommendation is "m.ban" or "org.matrix.mjolnir.ban") + return PolicyRecommendationTypes.Ban; + + return Recommendation; + } } public static class PolicyRecommendationTypes { -- cgit 1.5.1