From 8fca8152cedec71da2026bfdb8383cefde173e7f Mon Sep 17 00:00:00 2001 From: Rory& Date: Mon, 17 Mar 2025 10:39:16 +0100 Subject: Work --- MatrixAntiDmSpam/PolicyListFetcher.cs | 2 -- MatrixAntiDmSpam/PolicyStore.cs | 29 +++++++++++++++++++++++++++++ MatrixAntiDmSpam/Program.cs | 1 - 3 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 MatrixAntiDmSpam/PolicyStore.cs (limited to 'MatrixAntiDmSpam') diff --git a/MatrixAntiDmSpam/PolicyListFetcher.cs b/MatrixAntiDmSpam/PolicyListFetcher.cs index 0119527..ee80120 100644 --- a/MatrixAntiDmSpam/PolicyListFetcher.cs +++ b/MatrixAntiDmSpam/PolicyListFetcher.cs @@ -3,8 +3,6 @@ using LibMatrix.Homeservers; namespace MatrixAntiDmSpam; public class PolicyListFetcher(ILogger logger, AntiDmSpamConfiguration config, AuthenticatedHomeserverGeneric homeserver) : IHostedService { - - public async Task StartAsync(CancellationToken cancellationToken) { logger.LogInformation("Starting policy list fetcher"); await EnsurePolicyListsJoined(); diff --git a/MatrixAntiDmSpam/PolicyStore.cs b/MatrixAntiDmSpam/PolicyStore.cs new file mode 100644 index 0000000..1aa78d4 --- /dev/null +++ b/MatrixAntiDmSpam/PolicyStore.cs @@ -0,0 +1,29 @@ +using LibMatrix; +using System.Collections; +using LibMatrix.EventTypes.Spec.State.Policy; + +namespace MatrixAntiDmSpam; + +public class PolicyStore { + public Dictionary UserPolicies { get; } = []; + public Dictionary ServerPolicies { get; } = []; + public Dictionary RoomPolicies { get; } = []; + + public void AddPolicies(IEnumerable events) => events.ForEach(AddPolicy); + + public void AddPolicy(StateEventResponse evt) { + var eventKey = $"{evt.RoomId}:{evt.Type}:{evt.StateKey}"; + UserPolicies.ToList().ForEach(x => Console.WriteLine(x.Key)); + switch (evt.TypedContent) { + case UserPolicyRuleEventContent userPolicy: + UserPolicies[eventKey] = userPolicy; + break; + case ServerPolicyRuleEventContent serverPolicy: + ServerPolicies[eventKey] = serverPolicy; + break; + case RoomPolicyRuleEventContent roomPolicy: + RoomPolicies[eventKey] = roomPolicy; + break; + } + } +} \ No newline at end of file diff --git a/MatrixAntiDmSpam/Program.cs b/MatrixAntiDmSpam/Program.cs index cbf1dc9..39d8273 100644 --- a/MatrixAntiDmSpam/Program.cs +++ b/MatrixAntiDmSpam/Program.cs @@ -1,4 +1,3 @@ -using System.ComponentModel; using LibMatrix.Services; using LibMatrix.Utilities.Bot; using MatrixAntiDmSpam; -- cgit 1.5.1