about summary refs log tree commit diff
path: root/Utilities/LibMatrix.Utilities.Bot
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--Utilities/LibMatrix.Utilities.Bot/AppServiceConfiguration.cs2
-rw-r--r--Utilities/LibMatrix.Utilities.Bot/BotCommandInstaller.cs3
-rw-r--r--Utilities/LibMatrix.Utilities.Bot/Commands/HelpCommand.cs8
-rw-r--r--Utilities/LibMatrix.Utilities.Bot/Commands/PingCommand.cs6
-rw-r--r--Utilities/LibMatrix.Utilities.Bot/FileStorageProvider.cs6
-rw-r--r--Utilities/LibMatrix.Utilities.Bot/Interfaces/CommandContext.cs2
-rw-r--r--Utilities/LibMatrix.Utilities.Bot/Interfaces/ICommand.cs6
-rw-r--r--Utilities/LibMatrix.Utilities.Bot/LibMatrix.Utilities.Bot.csproj8
-rw-r--r--Utilities/LibMatrix.Utilities.Bot/LibMatrixBotConfiguration.cs2
-rw-r--r--Utilities/LibMatrix.Utilities.Bot/Services/CommandListenerHostedService.cs18
10 files changed, 26 insertions, 35 deletions
diff --git a/Utilities/LibMatrix.Utilities.Bot/AppServiceConfiguration.cs b/Utilities/LibMatrix.Utilities.Bot/AppServiceConfiguration.cs
index d8d1094..afda89e 100644
--- a/Utilities/LibMatrix.Utilities.Bot/AppServiceConfiguration.cs
+++ b/Utilities/LibMatrix.Utilities.Bot/AppServiceConfiguration.cs
@@ -84,4 +84,4 @@ public class AppServiceConfiguration {
 
         return yaml;
     }
-}
+}
\ No newline at end of file
diff --git a/Utilities/LibMatrix.Utilities.Bot/BotCommandInstaller.cs b/Utilities/LibMatrix.Utilities.Bot/BotCommandInstaller.cs
index 25a8d92..eb67424 100644
--- a/Utilities/LibMatrix.Utilities.Bot/BotCommandInstaller.cs
+++ b/Utilities/LibMatrix.Utilities.Bot/BotCommandInstaller.cs
@@ -34,6 +34,7 @@ public static class BotCommandInstaller {
             services.AddHostedService<CommandListenerHostedService>();
             // services.AddSingleton<IHostedService, CommandListenerHostedService>();
         }
+
         return services;
     }
-}
+}
\ No newline at end of file
diff --git a/Utilities/LibMatrix.Utilities.Bot/Commands/HelpCommand.cs b/Utilities/LibMatrix.Utilities.Bot/Commands/HelpCommand.cs
index 4fe1038..9937b3c 100644
--- a/Utilities/LibMatrix.Utilities.Bot/Commands/HelpCommand.cs
+++ b/Utilities/LibMatrix.Utilities.Bot/Commands/HelpCommand.cs
@@ -13,10 +13,8 @@ public class HelpCommand(IServiceProvider services) : ICommand {
         var sb = new StringBuilder();
         sb.AppendLine("Available commands:");
         var commands = services.GetServices<ICommand>().ToList();
-        foreach (var command in commands) {
-            sb.AppendLine($"- {command.Name}: {command.Description}");
-        }
+        foreach (var command in commands) sb.AppendLine($"- {command.Name}: {command.Description}");
 
-        await ctx.Room.SendMessageEventAsync(new RoomMessageEventContent(messageType: "m.notice", body: sb.ToString()));
+        await ctx.Room.SendMessageEventAsync(new RoomMessageEventContent("m.notice", sb.ToString()));
     }
-}
+}
\ No newline at end of file
diff --git a/Utilities/LibMatrix.Utilities.Bot/Commands/PingCommand.cs b/Utilities/LibMatrix.Utilities.Bot/Commands/PingCommand.cs
index 16712ea..b5fb868 100644
--- a/Utilities/LibMatrix.Utilities.Bot/Commands/PingCommand.cs
+++ b/Utilities/LibMatrix.Utilities.Bot/Commands/PingCommand.cs
@@ -7,7 +7,5 @@ public class PingCommand : ICommand {
     public string Name { get; } = "ping";
     public string Description { get; } = "Pong!";
 
-    public async Task Invoke(CommandContext ctx) {
-        await ctx.Room.SendMessageEventAsync(new RoomMessageEventContent(body: "pong!"));
-    }
-}
+    public async Task Invoke(CommandContext ctx) => await ctx.Room.SendMessageEventAsync(new RoomMessageEventContent(body: "pong!"));
+}
\ No newline at end of file
diff --git a/Utilities/LibMatrix.Utilities.Bot/FileStorageProvider.cs b/Utilities/LibMatrix.Utilities.Bot/FileStorageProvider.cs
index b66fbf5..b762937 100644
--- a/Utilities/LibMatrix.Utilities.Bot/FileStorageProvider.cs
+++ b/Utilities/LibMatrix.Utilities.Bot/FileStorageProvider.cs
@@ -14,9 +14,7 @@ public class FileStorageProvider : IStorageProvider {
     public FileStorageProvider(string targetPath) {
         Console.WriteLine($"Initialised FileStorageProvider with path {targetPath}");
         TargetPath = targetPath;
-        if (!Directory.Exists(targetPath)) {
-            Directory.CreateDirectory(targetPath);
-        }
+        if (!Directory.Exists(targetPath)) Directory.CreateDirectory(targetPath);
     }
 
     public async Task SaveObjectAsync<T>(string key, T value) => await File.WriteAllTextAsync(Path.Join(TargetPath, key), value?.ToJson());
@@ -31,4 +29,4 @@ public class FileStorageProvider : IStorageProvider {
         File.Delete(Path.Join(TargetPath, key));
         return Task.CompletedTask;
     }
-}
+}
\ No newline at end of file
diff --git a/Utilities/LibMatrix.Utilities.Bot/Interfaces/CommandContext.cs b/Utilities/LibMatrix.Utilities.Bot/Interfaces/CommandContext.cs
index 94ea846..e65f86d 100644
--- a/Utilities/LibMatrix.Utilities.Bot/Interfaces/CommandContext.cs
+++ b/Utilities/LibMatrix.Utilities.Bot/Interfaces/CommandContext.cs
@@ -19,4 +19,4 @@ public class CommandContext {
     public required AuthenticatedHomeserverGeneric Homeserver { get; set; }
 
     public async Task<EventIdResponse> Reply(RoomMessageEventContent content) => await Room.SendMessageEventAsync(content);
-}
+}
\ No newline at end of file
diff --git a/Utilities/LibMatrix.Utilities.Bot/Interfaces/ICommand.cs b/Utilities/LibMatrix.Utilities.Bot/Interfaces/ICommand.cs
index 82439e8..453a8fe 100644
--- a/Utilities/LibMatrix.Utilities.Bot/Interfaces/ICommand.cs
+++ b/Utilities/LibMatrix.Utilities.Bot/Interfaces/ICommand.cs
@@ -4,9 +4,7 @@ public interface ICommand {
     public string Name { get; }
     public string Description { get; }
 
-    public Task<bool> CanInvoke(CommandContext ctx) {
-        return Task.FromResult(true);
-    }
+    public Task<bool> CanInvoke(CommandContext ctx) => Task.FromResult(true);
 
     public Task Invoke(CommandContext ctx);
-}
+}
\ No newline at end of file
diff --git a/Utilities/LibMatrix.Utilities.Bot/LibMatrix.Utilities.Bot.csproj b/Utilities/LibMatrix.Utilities.Bot/LibMatrix.Utilities.Bot.csproj
index e16c00c..89ea5af 100644
--- a/Utilities/LibMatrix.Utilities.Bot/LibMatrix.Utilities.Bot.csproj
+++ b/Utilities/LibMatrix.Utilities.Bot/LibMatrix.Utilities.Bot.csproj
@@ -8,13 +8,13 @@
     </PropertyGroup>
 
     <ItemGroup>
-        <ProjectReference Include="..\..\LibMatrix\LibMatrix.csproj" />
+        <ProjectReference Include="..\..\LibMatrix\LibMatrix.csproj"/>
     </ItemGroup>
 
     <ItemGroup>
-        <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
-        <PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
-        <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
+        <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0"/>
+        <PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0"/>
+        <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0"/>
     </ItemGroup>
 
 
diff --git a/Utilities/LibMatrix.Utilities.Bot/LibMatrixBotConfiguration.cs b/Utilities/LibMatrix.Utilities.Bot/LibMatrixBotConfiguration.cs
index 27ce06b..d607637 100644
--- a/Utilities/LibMatrix.Utilities.Bot/LibMatrixBotConfiguration.cs
+++ b/Utilities/LibMatrix.Utilities.Bot/LibMatrixBotConfiguration.cs
@@ -8,4 +8,4 @@ public class LibMatrixBotConfiguration {
     public string AccessToken { get; set; } = "";
     public string Prefix { get; set; } = "?";
     public string? LogRoom { get; set; }
-}
+}
\ No newline at end of file
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