about summary refs log tree commit diff
path: root/ModerationBot.cs
diff options
context:
space:
mode:
authorEmma [it/its]@Rory& <root@rory.gay>2023-12-14 07:20:46 +0100
committerEmma [it/its]@Rory& <root@rory.gay>2023-12-14 07:20:46 +0100
commit98ffdd52b855d315d63cb1d75b0d51cfe200744a (patch)
tree45c7826e92d21fdd9408979befbb05fe22f05a18 /ModerationBot.cs
parentCleanup, move ArcaneLibs to submodule instead of parent submodule (diff)
downloadModerationBot-98ffdd52b855d315d63cb1d75b0d51cfe200744a.tar.xz
Cleanup
Diffstat (limited to 'ModerationBot.cs')
-rw-r--r--ModerationBot.cs19
1 files changed, 8 insertions, 11 deletions
diff --git a/ModerationBot.cs b/ModerationBot.cs
index 8a48b61..1be7bd5 100644
--- a/ModerationBot.cs
+++ b/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<ModerationBot> logger, ModerationBotConfiguration configuration,
-    HomeserverResolverService hsResolver, PolicyEngine engine) : IHostedService {
-    private readonly IEnumerable<ICommand> _commands;
-
+public class ModerationBot(AuthenticatedHomeserverGeneric hs, ILogger<ModerationBot> logger, ModerationBotConfiguration configuration, PolicyEngine engine) : IHostedService {
     private Task _listenerTask;
 
     // private GenericRoom _policyRoom;
-    private GenericRoom _logRoom;
-    private GenericRoom _controlRoom;
+    private GenericRoom? _logRoom;
+    private GenericRoom? _controlRoom;
 
     /// <summary>Triggered when the application host is ready to start the service.</summary>
     /// <param name="cancellationToken">Indicates that the start process has been aborted.</param>
@@ -63,6 +56,10 @@ public class ModerationBot(AuthenticatedHomeserverGeneric hs, ILogger<Moderation
         _controlRoom = hs.GetRoom(botData.ControlRoom);
         foreach (var configurationAdmin in configuration.Admins) {
             var pls = await _controlRoom.GetPowerLevelsAsync();
+            if (pls is null) {
+                await _logRoom?.SendMessageEventAsync(MessageFormatter.FormatWarning($"Control room has no m.room.power_levels?"));
+                continue;
+            }
             pls.SetUserPowerLevel(configurationAdmin, pls.GetUserPowerLevel(hs.UserId));
             await _controlRoom.SendStateEventAsync(RoomPowerLevelEventContent.EventId, pls);
         }