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 --- Utilities/LibMatrix.Utilities.Bot/AppServiceConfiguration.cs | 4 ++-- Utilities/LibMatrix.Utilities.Bot/BotCommandInstaller.cs | 4 ++-- Utilities/LibMatrix.Utilities.Bot/FileStorageProvider.cs | 4 ---- Utilities/LibMatrix.Utilities.Bot/Interfaces/CommandContext.cs | 6 +++--- 4 files changed, 7 insertions(+), 11 deletions(-) (limited to 'Utilities/LibMatrix.Utilities.Bot') diff --git a/Utilities/LibMatrix.Utilities.Bot/AppServiceConfiguration.cs b/Utilities/LibMatrix.Utilities.Bot/AppServiceConfiguration.cs index 99a789a..d8d1094 100644 --- a/Utilities/LibMatrix.Utilities.Bot/AppServiceConfiguration.cs +++ b/Utilities/LibMatrix.Utilities.Bot/AppServiceConfiguration.cs @@ -44,8 +44,8 @@ public class AppServiceConfiguration { else yaml += "protocols: []"; yaml += "\n"; - if (RateLimited is not null) - yaml += $"rate_limited: {RateLimited!.ToString().ToLower()}\n"; + if (RateLimited.HasValue) + yaml += $"rate_limited: {RateLimited.Value.ToString().ToLower()}\n"; else yaml += "rate_limited: false\n"; diff --git a/Utilities/LibMatrix.Utilities.Bot/BotCommandInstaller.cs b/Utilities/LibMatrix.Utilities.Bot/BotCommandInstaller.cs index 91ec1e8..25a8d92 100644 --- a/Utilities/LibMatrix.Utilities.Bot/BotCommandInstaller.cs +++ b/Utilities/LibMatrix.Utilities.Bot/BotCommandInstaller.cs @@ -21,8 +21,8 @@ public static class BotCommandInstaller { services.AddSingleton(); services.AddScoped(x => { - var config = x.GetService(); - var hsProvider = x.GetService(); + var config = x.GetService() ?? throw new Exception("No configuration found!"); + var hsProvider = x.GetService() ?? throw new Exception("No homeserver provider found!"); var hs = hsProvider.GetAuthenticatedWithToken(config.Homeserver, config.AccessToken).Result; return hs; diff --git a/Utilities/LibMatrix.Utilities.Bot/FileStorageProvider.cs b/Utilities/LibMatrix.Utilities.Bot/FileStorageProvider.cs index 46032c7..b66fbf5 100644 --- a/Utilities/LibMatrix.Utilities.Bot/FileStorageProvider.cs +++ b/Utilities/LibMatrix.Utilities.Bot/FileStorageProvider.cs @@ -1,13 +1,10 @@ using System.Text.Json; using ArcaneLibs.Extensions; using LibMatrix.Interfaces.Services; -using Microsoft.Extensions.Logging; namespace LibMatrix.Utilities.Bot; public class FileStorageProvider : IStorageProvider { - private readonly ILogger _logger; - public string TargetPath { get; } /// @@ -15,7 +12,6 @@ public class FileStorageProvider : IStorageProvider { /// /// public FileStorageProvider(string targetPath) { - new Logger(new LoggerFactory()).LogInformation("test"); Console.WriteLine($"Initialised FileStorageProvider with path {targetPath}"); TargetPath = targetPath; if (!Directory.Exists(targetPath)) { diff --git a/Utilities/LibMatrix.Utilities.Bot/Interfaces/CommandContext.cs b/Utilities/LibMatrix.Utilities.Bot/Interfaces/CommandContext.cs index 2d04e37..94ea846 100644 --- a/Utilities/LibMatrix.Utilities.Bot/Interfaces/CommandContext.cs +++ b/Utilities/LibMatrix.Utilities.Bot/Interfaces/CommandContext.cs @@ -5,8 +5,8 @@ using LibMatrix.RoomTypes; namespace LibMatrix.Utilities.Bot.Interfaces; public class CommandContext { - public GenericRoom Room { get; set; } - public StateEventResponse MessageEvent { get; set; } + public required GenericRoom Room { get; set; } + public required StateEventResponse MessageEvent { get; set; } public string MessageContentWithoutReply => (MessageEvent.TypedContent as RoomMessageEventContent)! @@ -16,7 +16,7 @@ public class CommandContext { public string CommandName => MessageContentWithoutReply.Split(' ')[0][1..]; public string[] Args => MessageContentWithoutReply.Split(' ')[1..]; - public AuthenticatedHomeserverGeneric Homeserver { get; set; } + public required AuthenticatedHomeserverGeneric Homeserver { get; set; } public async Task Reply(RoomMessageEventContent content) => await Room.SendMessageEventAsync(content); } -- cgit 1.4.1