about summary refs log tree commit diff
path: root/Utilities/LibMatrix.Utilities.Bot/Services/CommandListenerHostedService.cs
diff options
context:
space:
mode:
authorEmma [it/its]@Rory& <root@rory.gay>2024-02-09 16:33:14 +0100
committerEmma [it/its]@Rory& <root@rory.gay>2024-02-09 16:33:14 +0100
commit163e2a94f600ffe0f982e3f605264ff2f2fe312b (patch)
treeaf8fb4c8c468dde726a4773b1304aa22c59186ac /Utilities/LibMatrix.Utilities.Bot/Services/CommandListenerHostedService.cs
parentApply syntax style to LibMatrix (diff)
downloadLibMatrix-163e2a94f600ffe0f982e3f605264ff2f2fe312b.tar.xz
Apply syntax style to LibMatrix side projects
Diffstat (limited to '')
-rw-r--r--Utilities/LibMatrix.Utilities.Bot/Services/CommandListenerHostedService.cs18
1 files changed, 8 insertions, 10 deletions
diff --git a/Utilities/LibMatrix.Utilities.Bot/Services/CommandListenerHostedService.cs b/Utilities/LibMatrix.Utilities.Bot/Services/CommandListenerHostedService.cs
index 9949631..11ee740 100644
--- a/Utilities/LibMatrix.Utilities.Bot/Services/CommandListenerHostedService.cs
+++ b/Utilities/LibMatrix.Utilities.Bot/Services/CommandListenerHostedService.cs
@@ -18,7 +18,7 @@ public class CommandListenerHostedService : IHostedService {
 
     public CommandListenerHostedService(AuthenticatedHomeserverGeneric hs, ILogger<CommandListenerHostedService> logger, IServiceProvider services,
         LibMatrixBotConfiguration config) {
-        logger.LogInformation("{} instantiated!", this.GetType().Name);
+        logger.LogInformation("{} instantiated!", GetType().Name);
         _hs = hs;
         _logger = logger;
         _config = config;
@@ -44,7 +44,7 @@ public class CommandListenerHostedService : IHostedService {
             try {
                 var room = _hs.GetRoom(@event.RoomId);
                 // _logger.LogInformation(eventResponse.ToJson(indent: false));
-                if (@event is { Type: "m.room.message", TypedContent: RoomMessageEventContent message }) {
+                if (@event is { Type: "m.room.message", TypedContent: RoomMessageEventContent message })
                     if (message is { MessageType: "m.text" }) {
                         var messageContentWithoutReply =
                             message.Body.Split('\n', StringSplitOptions.RemoveEmptyEntries).SkipWhile(x => x.StartsWith(">")).Aggregate((x, y) => $"{x}\n{y}");
@@ -52,7 +52,7 @@ public class CommandListenerHostedService : IHostedService {
                             var command = _commands.FirstOrDefault(x => x.Name == messageContentWithoutReply.Split(' ')[0][_config.Prefix.Length..]);
                             if (command == null) {
                                 await room.SendMessageEventAsync(
-                                    new RoomMessageEventContent(messageType: "m.notice", body: "Command not found!"));
+                                    new RoomMessageEventContent("m.notice", "Command not found!"));
                                 return;
                             }
 
@@ -62,7 +62,7 @@ public class CommandListenerHostedService : IHostedService {
                                 Homeserver = _hs
                             };
 
-                            if (await command.CanInvoke(ctx)) {
+                            if (await command.CanInvoke(ctx))
                                 try {
                                     await command.Invoke(ctx);
                                 }
@@ -70,14 +70,11 @@ public class CommandListenerHostedService : IHostedService {
                                     await room.SendMessageEventAsync(
                                         MessageFormatter.FormatException("An error occurred during the execution of this command", e));
                                 }
-                            }
-                            else {
+                            else
                                 await room.SendMessageEventAsync(
-                                    new RoomMessageEventContent(messageType: "m.notice", body: "You do not have permission to run this command!"));
-                            }
+                                    new RoomMessageEventContent("m.notice", "You do not have permission to run this command!"));
                         }
                     }
-                }
             }
             catch (Exception e) {
                 _logger.LogError(e, "Error in command listener!");
@@ -94,6 +91,7 @@ public class CommandListenerHostedService : IHostedService {
             _logger.LogError("Could not shut down command listener task because it was null!");
             return;
         }
+
         await _listenerTask.WaitAsync(cancellationToken);
     }
-}
+}
\ No newline at end of file