From 5affd9f061e75f6575a2fe6715f9e8757cfe87e8 Mon Sep 17 00:00:00 2001 From: "Emma [it/its]@Rory&" Date: Thu, 14 Dec 2023 07:20:46 +0100 Subject: Cleanup --- .../LibMatrix.ExampleBot/Bot/Commands/CmdCommand.cs | 1 - .../LibMatrix.ExampleBot/Bot/FileStorageProvider.cs | 1 - .../Bot/Interfaces/CommandContext.cs | 1 - ExampleBots/LibMatrix.ExampleBot/Bot/MRUBot.cs | 1 - .../Bot/StartupTasks/ServerRoomSizeCalulator.cs | 2 -- ExampleBots/LibMatrix.ExampleBot/Program.cs | 2 -- ExampleBots/ModerationBot/Commands/BanMediaCommand.cs | 2 -- .../Commands/DbgAllRoomsArePolicyListsCommand.cs | 5 ----- .../Commands/DbgDumpActivePoliciesCommand.cs | 5 ----- .../Commands/DbgDumpAllStateTypesCommand.cs | 4 ---- ExampleBots/ModerationBot/Commands/JoinRoomCommand.cs | 5 ----- .../ModerationBot/Commands/JoinSpaceMembersCommand.cs | 4 ---- ExampleBots/ModerationBot/FirstRunTasks.cs | 1 - ExampleBots/ModerationBot/ModerationBot.cs | 19 ++++++++----------- ExampleBots/ModerationBot/PolicyEngine.cs | 15 +++++++-------- ExampleBots/ModerationBot/PolicyList.cs | 1 - .../StateEventTypes/Policies/BasePolicy.cs | 1 + .../Policies/Implementations/MediaPolicyHomeserver.cs | 1 - .../Implementations/MessagePolicyContainsText.cs | 1 - .../Policies/Implementations/UnknownPolicy.cs | 3 --- .../PluralContactBotPoC/Bot/AccountData/BotData.cs | 1 - .../PluralContactBotPoC/Bot/AccountData/SystemData.cs | 3 +-- ExampleBots/PluralContactBotPoC/Program.cs | 2 -- 23 files changed, 17 insertions(+), 64 deletions(-) (limited to 'ExampleBots') diff --git a/ExampleBots/LibMatrix.ExampleBot/Bot/Commands/CmdCommand.cs b/ExampleBots/LibMatrix.ExampleBot/Bot/Commands/CmdCommand.cs index ea42597..e690890 100644 --- a/ExampleBots/LibMatrix.ExampleBot/Bot/Commands/CmdCommand.cs +++ b/ExampleBots/LibMatrix.ExampleBot/Bot/Commands/CmdCommand.cs @@ -1,4 +1,3 @@ -using ArcaneLibs.Extensions; using ArcaneLibs.StringNormalisation; using LibMatrix.EventTypes.Spec; using LibMatrix.ExampleBot.Bot.Interfaces; diff --git a/ExampleBots/LibMatrix.ExampleBot/Bot/FileStorageProvider.cs b/ExampleBots/LibMatrix.ExampleBot/Bot/FileStorageProvider.cs index 935d53f..2c014de 100644 --- a/ExampleBots/LibMatrix.ExampleBot/Bot/FileStorageProvider.cs +++ b/ExampleBots/LibMatrix.ExampleBot/Bot/FileStorageProvider.cs @@ -1,6 +1,5 @@ using System.Text.Json; using ArcaneLibs.Extensions; -using LibMatrix.Extensions; using LibMatrix.Interfaces.Services; using Microsoft.Extensions.Logging; diff --git a/ExampleBots/LibMatrix.ExampleBot/Bot/Interfaces/CommandContext.cs b/ExampleBots/LibMatrix.ExampleBot/Bot/Interfaces/CommandContext.cs index 9b6ef7a..6dbb7f9 100644 --- a/ExampleBots/LibMatrix.ExampleBot/Bot/Interfaces/CommandContext.cs +++ b/ExampleBots/LibMatrix.ExampleBot/Bot/Interfaces/CommandContext.cs @@ -1,5 +1,4 @@ using LibMatrix.EventTypes.Spec; -using LibMatrix.Responses; using LibMatrix.RoomTypes; namespace LibMatrix.ExampleBot.Bot.Interfaces; diff --git a/ExampleBots/LibMatrix.ExampleBot/Bot/MRUBot.cs b/ExampleBots/LibMatrix.ExampleBot/Bot/MRUBot.cs index 8cf4f1f..8e6cd6a 100644 --- a/ExampleBots/LibMatrix.ExampleBot/Bot/MRUBot.cs +++ b/ExampleBots/LibMatrix.ExampleBot/Bot/MRUBot.cs @@ -3,7 +3,6 @@ using ArcaneLibs.Extensions; using LibMatrix.EventTypes.Spec; using LibMatrix.EventTypes.Spec.State; using LibMatrix.ExampleBot.Bot.Interfaces; -using LibMatrix.Extensions; using LibMatrix.Helpers; using LibMatrix.Homeservers; using LibMatrix.Services; diff --git a/ExampleBots/LibMatrix.ExampleBot/Bot/StartupTasks/ServerRoomSizeCalulator.cs b/ExampleBots/LibMatrix.ExampleBot/Bot/StartupTasks/ServerRoomSizeCalulator.cs index 890db85..2f6e0b0 100644 --- a/ExampleBots/LibMatrix.ExampleBot/Bot/StartupTasks/ServerRoomSizeCalulator.cs +++ b/ExampleBots/LibMatrix.ExampleBot/Bot/StartupTasks/ServerRoomSizeCalulator.cs @@ -1,9 +1,7 @@ using System.Diagnostics.CodeAnalysis; -using ArcaneLibs.Extensions; using LibMatrix.ExampleBot.Bot.Interfaces; using LibMatrix.Homeservers; using LibMatrix.Services; -using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; diff --git a/ExampleBots/LibMatrix.ExampleBot/Program.cs b/ExampleBots/LibMatrix.ExampleBot/Program.cs index 6d8775e..25ce07d 100644 --- a/ExampleBots/LibMatrix.ExampleBot/Program.cs +++ b/ExampleBots/LibMatrix.ExampleBot/Program.cs @@ -3,8 +3,6 @@ using ArcaneLibs; using LibMatrix.ExampleBot.Bot; using LibMatrix.ExampleBot.Bot.Interfaces; -using LibMatrix.ExampleBot.Bot.StartupTasks; -using LibMatrix.Extensions; using LibMatrix.Services; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; diff --git a/ExampleBots/ModerationBot/Commands/BanMediaCommand.cs b/ExampleBots/ModerationBot/Commands/BanMediaCommand.cs index 9e49b22..535fd4f 100644 --- a/ExampleBots/ModerationBot/Commands/BanMediaCommand.cs +++ b/ExampleBots/ModerationBot/Commands/BanMediaCommand.cs @@ -1,4 +1,3 @@ -using System.Buffers.Text; using System.Security.Cryptography; using ArcaneLibs.Extensions; using LibMatrix; @@ -7,7 +6,6 @@ using LibMatrix.Helpers; using LibMatrix.Services; using LibMatrix.Utilities.Bot.Interfaces; using ModerationBot.AccountData; -using ModerationBot.StateEventTypes; using ModerationBot.StateEventTypes.Policies.Implementations; namespace ModerationBot.Commands; diff --git a/ExampleBots/ModerationBot/Commands/DbgAllRoomsArePolicyListsCommand.cs b/ExampleBots/ModerationBot/Commands/DbgAllRoomsArePolicyListsCommand.cs index 327a9a4..f578f53 100644 --- a/ExampleBots/ModerationBot/Commands/DbgAllRoomsArePolicyListsCommand.cs +++ b/ExampleBots/ModerationBot/Commands/DbgAllRoomsArePolicyListsCommand.cs @@ -1,14 +1,9 @@ -using System.Buffers.Text; -using System.Security.Cryptography; -using ArcaneLibs.Extensions; -using LibMatrix; using LibMatrix.EventTypes.Spec; using LibMatrix.Helpers; using LibMatrix.RoomTypes; using LibMatrix.Services; using LibMatrix.Utilities.Bot.Interfaces; using ModerationBot.AccountData; -using ModerationBot.StateEventTypes; namespace ModerationBot.Commands; diff --git a/ExampleBots/ModerationBot/Commands/DbgDumpActivePoliciesCommand.cs b/ExampleBots/ModerationBot/Commands/DbgDumpActivePoliciesCommand.cs index 35c95f8..285d792 100644 --- a/ExampleBots/ModerationBot/Commands/DbgDumpActivePoliciesCommand.cs +++ b/ExampleBots/ModerationBot/Commands/DbgDumpActivePoliciesCommand.cs @@ -1,14 +1,9 @@ -using System.Buffers.Text; -using System.Security.Cryptography; using ArcaneLibs.Extensions; -using LibMatrix; using LibMatrix.EventTypes.Spec; -using LibMatrix.Helpers; using LibMatrix.RoomTypes; using LibMatrix.Services; using LibMatrix.Utilities.Bot.Interfaces; using ModerationBot.AccountData; -using ModerationBot.StateEventTypes; namespace ModerationBot.Commands; diff --git a/ExampleBots/ModerationBot/Commands/DbgDumpAllStateTypesCommand.cs b/ExampleBots/ModerationBot/Commands/DbgDumpAllStateTypesCommand.cs index 0013065..3727877 100644 --- a/ExampleBots/ModerationBot/Commands/DbgDumpAllStateTypesCommand.cs +++ b/ExampleBots/ModerationBot/Commands/DbgDumpAllStateTypesCommand.cs @@ -1,14 +1,10 @@ -using System.Buffers.Text; -using System.Security.Cryptography; using ArcaneLibs.Extensions; using LibMatrix; using LibMatrix.EventTypes.Spec; -using LibMatrix.Helpers; using LibMatrix.RoomTypes; using LibMatrix.Services; using LibMatrix.Utilities.Bot.Interfaces; using ModerationBot.AccountData; -using ModerationBot.StateEventTypes; namespace ModerationBot.Commands; diff --git a/ExampleBots/ModerationBot/Commands/JoinRoomCommand.cs b/ExampleBots/ModerationBot/Commands/JoinRoomCommand.cs index 7496a07..eb22a70 100644 --- a/ExampleBots/ModerationBot/Commands/JoinRoomCommand.cs +++ b/ExampleBots/ModerationBot/Commands/JoinRoomCommand.cs @@ -1,13 +1,8 @@ -using System.Buffers.Text; -using System.Security.Cryptography; -using ArcaneLibs.Extensions; -using LibMatrix; using LibMatrix.EventTypes.Spec; using LibMatrix.Helpers; using LibMatrix.Services; using LibMatrix.Utilities.Bot.Interfaces; using ModerationBot.AccountData; -using ModerationBot.StateEventTypes; namespace ModerationBot.Commands; diff --git a/ExampleBots/ModerationBot/Commands/JoinSpaceMembersCommand.cs b/ExampleBots/ModerationBot/Commands/JoinSpaceMembersCommand.cs index 6e64f6f..da77b05 100644 --- a/ExampleBots/ModerationBot/Commands/JoinSpaceMembersCommand.cs +++ b/ExampleBots/ModerationBot/Commands/JoinSpaceMembersCommand.cs @@ -1,14 +1,10 @@ -using System.Buffers.Text; -using System.Security.Cryptography; using ArcaneLibs.Extensions; -using LibMatrix; using LibMatrix.EventTypes.Spec; using LibMatrix.Helpers; using LibMatrix.RoomTypes; using LibMatrix.Services; using LibMatrix.Utilities.Bot.Interfaces; using ModerationBot.AccountData; -using ModerationBot.StateEventTypes; namespace ModerationBot.Commands; diff --git a/ExampleBots/ModerationBot/FirstRunTasks.cs b/ExampleBots/ModerationBot/FirstRunTasks.cs index 83356bf..9dece1d 100644 --- a/ExampleBots/ModerationBot/FirstRunTasks.cs +++ b/ExampleBots/ModerationBot/FirstRunTasks.cs @@ -1,5 +1,4 @@ using LibMatrix; -using LibMatrix.EventTypes.Spec.State; using LibMatrix.Homeservers; using LibMatrix.Responses; using ModerationBot.AccountData; diff --git a/ExampleBots/ModerationBot/ModerationBot.cs b/ExampleBots/ModerationBot/ModerationBot.cs index 8a48b61..1be7bd5 100644 --- a/ExampleBots/ModerationBot/ModerationBot.cs +++ b/ExampleBots/ModerationBot/ModerationBot.cs @@ -1,32 +1,25 @@ -using System.Security.Cryptography; -using System.Text.RegularExpressions; using ArcaneLibs.Extensions; using LibMatrix; using LibMatrix.EventTypes.Spec; using LibMatrix.EventTypes.Spec.State; +using LibMatrix.EventTypes.Spec.State.Policy; using LibMatrix.Helpers; using LibMatrix.Homeservers; -using LibMatrix.Responses; using LibMatrix.RoomTypes; using LibMatrix.Services; -using LibMatrix.Utilities.Bot.Interfaces; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using ModerationBot.AccountData; -using ModerationBot.StateEventTypes; using ModerationBot.StateEventTypes.Policies; namespace ModerationBot; -public class ModerationBot(AuthenticatedHomeserverGeneric hs, ILogger logger, ModerationBotConfiguration configuration, - HomeserverResolverService hsResolver, PolicyEngine engine) : IHostedService { - private readonly IEnumerable _commands; - +public class ModerationBot(AuthenticatedHomeserverGeneric hs, ILogger logger, ModerationBotConfiguration configuration, PolicyEngine engine) : IHostedService { private Task _listenerTask; // private GenericRoom _policyRoom; - private GenericRoom _logRoom; - private GenericRoom _controlRoom; + private GenericRoom? _logRoom; + private GenericRoom? _controlRoom; /// Triggered when the application host is ready to start the service. /// Indicates that the start process has been aborted. @@ -63,6 +56,10 @@ public class ModerationBot(AuthenticatedHomeserverGeneric hs, ILogger logger, ModerationBotConfiguration configuration, HomeserverResolverService hsResolver) { private Dictionary PolicyListAccountData { get; set; } = new(); + // ReSharper disable once MemberCanBePrivate.Global public List ActivePolicyLists { get; set; } = new(); public List ActivePolicies { get; set; } = new(); public Dictionary> ActivePoliciesByType { get; set; } = new(); @@ -47,8 +46,8 @@ public class PolicyEngine(AuthenticatedHomeserverGeneric hs, ILogger(); - if (policy.Entity is null) continue; + var policy = policyEntry.TypedContent is BasePolicy ? policyEntry.TypedContent as BasePolicy : policyEntry.RawContent.Deserialize(); + if (policy?.Entity is null) continue; policy.PolicyList = activePolicyList; policy.OriginalEvent = policyEntry; activePolicies.Add(policy); @@ -152,7 +151,7 @@ public class PolicyEngine(AuthenticatedHomeserverGeneric hs, ILogger diff --git a/ExampleBots/PluralContactBotPoC/Bot/AccountData/BotData.cs b/ExampleBots/PluralContactBotPoC/Bot/AccountData/BotData.cs index 5d11432..2adcbb3 100644 --- a/ExampleBots/PluralContactBotPoC/Bot/AccountData/BotData.cs +++ b/ExampleBots/PluralContactBotPoC/Bot/AccountData/BotData.cs @@ -1,6 +1,5 @@ using System.Text.Json.Serialization; using LibMatrix.EventTypes; -using LibMatrix.Helpers; using LibMatrix.Interfaces; namespace PluralContactBotPoC.Bot.AccountData; diff --git a/ExampleBots/PluralContactBotPoC/Bot/AccountData/SystemData.cs b/ExampleBots/PluralContactBotPoC/Bot/AccountData/SystemData.cs index 42edd23..ad8ab1d 100644 --- a/ExampleBots/PluralContactBotPoC/Bot/AccountData/SystemData.cs +++ b/ExampleBots/PluralContactBotPoC/Bot/AccountData/SystemData.cs @@ -1,6 +1,5 @@ using System.Text.Json.Serialization; using LibMatrix.EventTypes; -using LibMatrix.Helpers; using LibMatrix.Interfaces; namespace PluralContactBotPoC.Bot.StateEventTypes; @@ -8,7 +7,7 @@ namespace PluralContactBotPoC.Bot.StateEventTypes; [MatrixEvent(EventName = "gay.rory.plural_contact_bot.system_data")] public class SystemData : EventContent { [JsonPropertyName("control_room")] - public string ControlRoom { get; set; } = null!; + public required string ControlRoom { get; set; } [JsonPropertyName("system_members")] public List Members { get; set; } = new(); [JsonPropertyName("dm_space")] diff --git a/ExampleBots/PluralContactBotPoC/Program.cs b/ExampleBots/PluralContactBotPoC/Program.cs index f8d93c6..f65f2e9 100644 --- a/ExampleBots/PluralContactBotPoC/Program.cs +++ b/ExampleBots/PluralContactBotPoC/Program.cs @@ -1,13 +1,11 @@ // See https://aka.ms/new-console-template for more information using System.Text.Json; -using System.Text.Json.Serialization; using ArcaneLibs.Extensions; using LibMatrix.Services; using LibMatrix.Utilities.Bot; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using PluralContactBotPoC; using PluralContactBotPoC.Bot; Console.WriteLine("Hello, World!"); -- cgit 1.4.1