From 8fca8152cedec71da2026bfdb8383cefde173e7f Mon Sep 17 00:00:00 2001 From: Rory& Date: Mon, 17 Mar 2025 10:39:16 +0100 Subject: Work --- .idea/.idea.MatrixAntiDmSpam/.idea/vcs.xml | 4 +++- LibMatrix | 2 +- MatrixAntiDmSpam.sln.DotSettings.user | 2 ++ MatrixAntiDmSpam/PolicyListFetcher.cs | 2 -- MatrixAntiDmSpam/PolicyStore.cs | 29 +++++++++++++++++++++++++++++ MatrixAntiDmSpam/Program.cs | 1 - 6 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 MatrixAntiDmSpam/PolicyStore.cs diff --git a/.idea/.idea.MatrixAntiDmSpam/.idea/vcs.xml b/.idea/.idea.MatrixAntiDmSpam/.idea/vcs.xml index d843f34..35eb1dd 100644 --- a/.idea/.idea.MatrixAntiDmSpam/.idea/vcs.xml +++ b/.idea/.idea.MatrixAntiDmSpam/.idea/vcs.xml @@ -1,4 +1,6 @@ - + + + \ No newline at end of file diff --git a/LibMatrix b/LibMatrix index 08b552f..ee0f3ff 160000 --- a/LibMatrix +++ b/LibMatrix @@ -1 +1 @@ -Subproject commit 08b552fc3ad6e81d8ebddc238043681da90673b3 +Subproject commit ee0f3ff6ae641880c4d8b7308f02839d80c0af88 diff --git a/MatrixAntiDmSpam.sln.DotSettings.user b/MatrixAntiDmSpam.sln.DotSettings.user index c8aa6db..fe3cfa4 100644 --- a/MatrixAntiDmSpam.sln.DotSettings.user +++ b/MatrixAntiDmSpam.sln.DotSettings.user @@ -1,5 +1,7 @@  ForceIncluded + ForceIncluded + ForceIncluded ForceIncluded ForceIncluded ForceIncluded \ No newline at end of file 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