From 163e2a94f600ffe0f982e3f605264ff2f2fe312b Mon Sep 17 00:00:00 2001 From: "Emma [it/its]@Rory&" Date: Fri, 9 Feb 2024 16:33:14 +0100 Subject: Apply syntax style to LibMatrix side projects --- .../Services/CommandListenerHostedService.cs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'Utilities/LibMatrix.Utilities.Bot/Services/CommandListenerHostedService.cs') 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 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 -- cgit 1.4.1