about summary refs log tree commit diff
path: root/LibMatrix.EventTypes
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2024-11-22 06:38:42 +0100
committerRory& <root@rory.gay>2024-11-22 06:38:42 +0100
commitbb0c00531dfacd30ecef1ac4444c2e3281fa36b8 (patch)
tree8c96bfc792370a0385a0e4acec80da90192f1471 /LibMatrix.EventTypes
parentHSE updates (diff)
downloadLibMatrix-bb0c00531dfacd30ecef1ac4444c2e3281fa36b8.tar.xz
Extra draupnir/policy event work github/master
Diffstat (limited to 'LibMatrix.EventTypes')
-rw-r--r--LibMatrix.EventTypes/Interop/Draupnir/DraupnirProtectedRoomsData.cs11
-rw-r--r--LibMatrix.EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs9
2 files changed, 20 insertions, 0 deletions
diff --git a/LibMatrix.EventTypes/Interop/Draupnir/DraupnirProtectedRoomsData.cs b/LibMatrix.EventTypes/Interop/Draupnir/DraupnirProtectedRoomsData.cs
new file mode 100644

index 0000000..1917239 --- /dev/null +++ b/LibMatrix.EventTypes/Interop/Draupnir/DraupnirProtectedRoomsData.cs
@@ -0,0 +1,11 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.EventTypes.Interop.Draupnir; + +[MatrixEvent(EventName = EventId)] +public class DraupnirProtectedRoomsData : EventContent { + public const string EventId = "org.matrix.mjolnir.protected_rooms"; + + [JsonPropertyName("rooms")] + public List<string> Rooms { get; set; } = new(); +} \ No newline at end of file diff --git a/LibMatrix.EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs b/LibMatrix.EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs
index 5bfd77b..0569477 100644 --- a/LibMatrix.EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs +++ b/LibMatrix.EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs
@@ -1,5 +1,6 @@ using System.Security.Cryptography; using System.Text.Json.Serialization; +using System.Text.RegularExpressions; using ArcaneLibs.Attributes; using ArcaneLibs.Extensions; @@ -91,6 +92,14 @@ public abstract class PolicyRuleEventContent : EventContent { } public string GetDraupnir2StateKey() => Convert.ToBase64String(SHA256.HashData($"{Entity}{Recommendation}".AsBytes().ToArray())); + + public Regex GetEntityRegex() => new(Entity.Replace(".", "\\.").Replace("*", ".*").Replace("?", ".")); + + public bool EntityMatches(string entity) => + Entity == entity + || (Entity.Contains("*") || Entity.Contains("?") + ? GetEntityRegex().IsMatch(entity) + : entity == Entity); } public static class PolicyRecommendationTypes {