about summary refs log tree commit diff
path: root/MatrixAntiDmSpam
diff options
context:
space:
mode:
Diffstat (limited to 'MatrixAntiDmSpam')
-rw-r--r--MatrixAntiDmSpam/PolicyListFetcher.cs2
-rw-r--r--MatrixAntiDmSpam/PolicyStore.cs29
-rw-r--r--MatrixAntiDmSpam/Program.cs1
3 files changed, 29 insertions, 3 deletions
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<PolicyListFetcher> 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<string, UserPolicyRuleEventContent> UserPolicies { get; } = []; + public Dictionary<string, ServerPolicyRuleEventContent> ServerPolicies { get; } = []; + public Dictionary<string, RoomPolicyRuleEventContent> RoomPolicies { get; } = []; + + public void AddPolicies(IEnumerable<StateEventResponse> 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;