about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-03-17 10:39:16 +0100
committerRory& <root@rory.gay>2025-03-17 10:39:16 +0100
commit8fca8152cedec71da2026bfdb8383cefde173e7f (patch)
treeb8a93cdc512e8d6277638750cd2c03004c8cc799
parentInitial commit (diff)
downloadMatrixAntiDmSpam-8fca8152cedec71da2026bfdb8383cefde173e7f.tar.xz
Work
-rw-r--r--.idea/.idea.MatrixAntiDmSpam/.idea/vcs.xml4
m---------LibMatrix0
-rw-r--r--MatrixAntiDmSpam.sln.DotSettings.user2
-rw-r--r--MatrixAntiDmSpam/PolicyListFetcher.cs2
-rw-r--r--MatrixAntiDmSpam/PolicyStore.cs29
-rw-r--r--MatrixAntiDmSpam/Program.cs1
6 files changed, 34 insertions, 4 deletions
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 @@ <?xml version="1.0" encoding="UTF-8"?> <project version="4"> - <component name="VcsDirectoryMappings" defaultProject="true" /> + <component name="VcsDirectoryMappings"> + <mapping directory="" vcs="Git" /> + </component> </project> \ No newline at end of file diff --git a/LibMatrix b/LibMatrix -Subproject 08b552fc3ad6e81d8ebddc238043681da90673b +Subproject ee0f3ff6ae641880c4d8b7308f02839d80c0af8 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 @@ <wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> <s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AExceptionDispatchInfo_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fea51ca5e833244688d7ca912cfc70784d19c00_003F97_003Ffb30ee1f_003FExceptionDispatchInfo_002Ecs/@EntryIndexedValue">ForceIncluded</s:String> + <s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AHashtable_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fea51ca5e833244688d7ca912cfc70784d19c00_003Fd2_003F20632896_003FHashtable_002Ecs/@EntryIndexedValue">ForceIncluded</s:String> + <s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AList_00601_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fea51ca5e833244688d7ca912cfc70784d19c00_003F65_003Fb77a719c_003FList_00601_002Ecs/@EntryIndexedValue">ForceIncluded</s:String> <s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AObjectExtensions_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F8fd5e96d6574456095123be1ecfbdfa914200_003Fe2_003F3561a383_003FObjectExtensions_002Ecs/@EntryIndexedValue">ForceIncluded</s:String> <s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AServiceCollectionHostedServiceExtensions_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Ff13297a632424a6abffea4dd75a36a75d128_003Ff9_003Fb35aae11_003FServiceCollectionHostedServiceExtensions_002Ecs/@EntryIndexedValue">ForceIncluded</s:String> <s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AStackFrameIterator_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fea51ca5e833244688d7ca912cfc70784d19c00_003F86_003F8b4aa64e_003FStackFrameIterator_002Ecs/@EntryIndexedValue">ForceIncluded</s:String></wpf:ResourceDictionary> \ 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<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;