about summary refs log tree commit diff
path: root/Utilities
diff options
context:
space:
mode:
Diffstat (limited to 'Utilities')
-rw-r--r--Utilities/LibMatrix.DebugDataValidationApi/Controllers/ValidationController.cs5
-rw-r--r--Utilities/LibMatrix.JsonSerializerContextGenerator/EventSerializerContexts.g.cs99
-rw-r--r--Utilities/LibMatrix.JsonSerializerContextGenerator/Program.cs28
-rw-r--r--Utilities/LibMatrix.Utilities.Bot/AppServiceConfiguration.cs4
-rw-r--r--Utilities/LibMatrix.Utilities.Bot/BotCommandInstaller.cs4
-rw-r--r--Utilities/LibMatrix.Utilities.Bot/FileStorageProvider.cs4
-rw-r--r--Utilities/LibMatrix.Utilities.Bot/Interfaces/CommandContext.cs6
7 files changed, 28 insertions, 122 deletions
diff --git a/Utilities/LibMatrix.DebugDataValidationApi/Controllers/ValidationController.cs b/Utilities/LibMatrix.DebugDataValidationApi/Controllers/ValidationController.cs
index 81753d1..1b93614 100644
--- a/Utilities/LibMatrix.DebugDataValidationApi/Controllers/ValidationController.cs
+++ b/Utilities/LibMatrix.DebugDataValidationApi/Controllers/ValidationController.cs
@@ -7,16 +7,15 @@ namespace LibMatrix.DebugDataValidationApi.Controllers;
 [ApiController]
 [Route("/")]
 public class ValidationController(ILogger<ValidationController> logger) : ControllerBase {
-    private readonly ILogger<ValidationController> _logger = logger;
 
     [HttpPost("/validate/{type}")]
     public Task<bool> Get([FromRoute] string type, [FromBody] JsonElement content) {
         var t = Type.GetType(type);
         if (t is null) {
-            Console.WriteLine($"Type `{type}` does not exist!");
+            logger.LogWarning($"Type `{type}` does not exist!");
             throw new ArgumentException($"Unknown type {type}!");
         }
-        Console.WriteLine($"Validating {type}...");
+        logger.LogInformation($"Validating {type}...");
         return Task.FromResult(content.FindExtraJsonElementFields(t, "$"));
     }
 }
diff --git a/Utilities/LibMatrix.JsonSerializerContextGenerator/EventSerializerContexts.g.cs b/Utilities/LibMatrix.JsonSerializerContextGenerator/EventSerializerContexts.g.cs
deleted file mode 100644
index 1ca32dd..0000000
--- a/Utilities/LibMatrix.JsonSerializerContextGenerator/EventSerializerContexts.g.cs
+++ /dev/null
@@ -1,99 +0,0 @@
-[System.Text.Json.Serialization.JsonSourceGenerationOptions(WriteIndented = true)]
-[System.Text.Json.Serialization.JsonSerializable(typeof(LibMatrix.EventTypes.UnknownEventContent))]
-internal partial class UnknownEventContentSerializerContext : System.Text.Json.Serialization.JsonSerializerContext { }
-
-[System.Text.Json.Serialization.JsonSourceGenerationOptions(WriteIndented = true)]
-[System.Text.Json.Serialization.JsonSerializable(typeof(LibMatrix.EventTypes.Spec.RoomMessageEventContent))]
-internal partial class RoomMessageEventContentSerializerContext : System.Text.Json.Serialization.JsonSerializerContext { }
-
-[System.Text.Json.Serialization.JsonSourceGenerationOptions(WriteIndented = true)]
-[System.Text.Json.Serialization.JsonSerializable(typeof(LibMatrix.EventTypes.Spec.State.PresenceEventContent))]
-internal partial class PresenceEventContentSerializerContext : System.Text.Json.Serialization.JsonSerializerContext { }
-
-[System.Text.Json.Serialization.JsonSourceGenerationOptions(WriteIndented = true)]
-[System.Text.Json.Serialization.JsonSerializable(typeof(LibMatrix.EventTypes.Spec.State.RoomTypingEventContent))]
-internal partial class RoomTypingEventContentSerializerContext : System.Text.Json.Serialization.JsonSerializerContext { }
-
-[System.Text.Json.Serialization.JsonSourceGenerationOptions(WriteIndented = true)]
-[System.Text.Json.Serialization.JsonSerializable(typeof(LibMatrix.EventTypes.Spec.State.ServerPolicyRuleEventContent))]
-internal partial class ServerPolicyRuleEventContentSerializerContext : System.Text.Json.Serialization.JsonSerializerContext { }
-
-[System.Text.Json.Serialization.JsonSourceGenerationOptions(WriteIndented = true)]
-[System.Text.Json.Serialization.JsonSerializable(typeof(LibMatrix.EventTypes.Spec.State.UserPolicyRuleEventContent))]
-internal partial class UserPolicyRuleEventContentSerializerContext : System.Text.Json.Serialization.JsonSerializerContext { }
-
-[System.Text.Json.Serialization.JsonSourceGenerationOptions(WriteIndented = true)]
-[System.Text.Json.Serialization.JsonSerializable(typeof(LibMatrix.EventTypes.Spec.State.RoomPolicyRuleEventContent))]
-internal partial class RoomPolicyRuleEventContentSerializerContext : System.Text.Json.Serialization.JsonSerializerContext { }
-
-[System.Text.Json.Serialization.JsonSourceGenerationOptions(WriteIndented = true)]
-[System.Text.Json.Serialization.JsonSerializable(typeof(LibMatrix.EventTypes.Spec.State.RoomAliasEventContent))]
-internal partial class RoomAliasEventContentSerializerContext : System.Text.Json.Serialization.JsonSerializerContext { }
-
-[System.Text.Json.Serialization.JsonSourceGenerationOptions(WriteIndented = true)]
-[System.Text.Json.Serialization.JsonSerializable(typeof(LibMatrix.EventTypes.Spec.State.RoomAvatarEventContent))]
-internal partial class RoomAvatarEventContentSerializerContext : System.Text.Json.Serialization.JsonSerializerContext { }
-
-[System.Text.Json.Serialization.JsonSourceGenerationOptions(WriteIndented = true)]
-[System.Text.Json.Serialization.JsonSerializable(typeof(LibMatrix.EventTypes.Spec.State.RoomCanonicalAliasEventContent))]
-internal partial class RoomCanonicalAliasEventContentSerializerContext : System.Text.Json.Serialization.JsonSerializerContext { }
-
-[System.Text.Json.Serialization.JsonSourceGenerationOptions(WriteIndented = true)]
-[System.Text.Json.Serialization.JsonSerializable(typeof(LibMatrix.EventTypes.Spec.State.RoomCreateEventContent))]
-internal partial class RoomCreateEventContentSerializerContext : System.Text.Json.Serialization.JsonSerializerContext { }
-
-[System.Text.Json.Serialization.JsonSourceGenerationOptions(WriteIndented = true)]
-[System.Text.Json.Serialization.JsonSerializable(typeof(LibMatrix.EventTypes.Spec.State.RoomEncryptionEventContent))]
-internal partial class RoomEncryptionEventContentSerializerContext : System.Text.Json.Serialization.JsonSerializerContext { }
-
-[System.Text.Json.Serialization.JsonSourceGenerationOptions(WriteIndented = true)]
-[System.Text.Json.Serialization.JsonSerializable(typeof(LibMatrix.EventTypes.Spec.State.RoomGuestAccessEventContent))]
-internal partial class RoomGuestAccessEventContentSerializerContext : System.Text.Json.Serialization.JsonSerializerContext { }
-
-[System.Text.Json.Serialization.JsonSourceGenerationOptions(WriteIndented = true)]
-[System.Text.Json.Serialization.JsonSerializable(typeof(LibMatrix.EventTypes.Spec.State.RoomHistoryVisibilityEventContent))]
-internal partial class RoomHistoryVisibilityEventContentSerializerContext : System.Text.Json.Serialization.JsonSerializerContext { }
-
-[System.Text.Json.Serialization.JsonSourceGenerationOptions(WriteIndented = true)]
-[System.Text.Json.Serialization.JsonSerializable(typeof(LibMatrix.EventTypes.Spec.State.RoomJoinRulesEventContent))]
-internal partial class RoomJoinRulesEventContentSerializerContext : System.Text.Json.Serialization.JsonSerializerContext { }
-
-[System.Text.Json.Serialization.JsonSourceGenerationOptions(WriteIndented = true)]
-[System.Text.Json.Serialization.JsonSerializable(typeof(LibMatrix.EventTypes.Spec.State.RoomMemberEventContent))]
-internal partial class RoomMemberEventContentSerializerContext : System.Text.Json.Serialization.JsonSerializerContext { }
-
-[System.Text.Json.Serialization.JsonSourceGenerationOptions(WriteIndented = true)]
-[System.Text.Json.Serialization.JsonSerializable(typeof(LibMatrix.EventTypes.Spec.State.RoomNameEventContent))]
-internal partial class RoomNameEventContentSerializerContext : System.Text.Json.Serialization.JsonSerializerContext { }
-
-[System.Text.Json.Serialization.JsonSourceGenerationOptions(WriteIndented = true)]
-[System.Text.Json.Serialization.JsonSerializable(typeof(LibMatrix.EventTypes.Spec.State.RoomPinnedEventContent))]
-internal partial class RoomPinnedEventContentSerializerContext : System.Text.Json.Serialization.JsonSerializerContext { }
-
-[System.Text.Json.Serialization.JsonSourceGenerationOptions(WriteIndented = true)]
-[System.Text.Json.Serialization.JsonSerializable(typeof(LibMatrix.EventTypes.Spec.State.RoomPowerLevelEventContent))]
-internal partial class RoomPowerLevelEventContentSerializerContext : System.Text.Json.Serialization.JsonSerializerContext { }
-
-[System.Text.Json.Serialization.JsonSourceGenerationOptions(WriteIndented = true)]
-[System.Text.Json.Serialization.JsonSerializable(typeof(LibMatrix.EventTypes.Spec.State.RoomServerACLEventContent))]
-internal partial class RoomServerACLEventContentSerializerContext : System.Text.Json.Serialization.JsonSerializerContext { }
-
-[System.Text.Json.Serialization.JsonSourceGenerationOptions(WriteIndented = true)]
-[System.Text.Json.Serialization.JsonSerializable(typeof(LibMatrix.EventTypes.Spec.State.RoomTopicEventContent))]
-internal partial class RoomTopicEventContentSerializerContext : System.Text.Json.Serialization.JsonSerializerContext { }
-
-[System.Text.Json.Serialization.JsonSourceGenerationOptions(WriteIndented = true)]
-[System.Text.Json.Serialization.JsonSerializable(typeof(LibMatrix.EventTypes.Spec.State.SpaceChildEventContent))]
-internal partial class SpaceChildEventContentSerializerContext : System.Text.Json.Serialization.JsonSerializerContext { }
-
-[System.Text.Json.Serialization.JsonSourceGenerationOptions(WriteIndented = true)]
-[System.Text.Json.Serialization.JsonSerializable(typeof(LibMatrix.EventTypes.Spec.State.SpaceParentEventContent))]
-internal partial class SpaceParentEventContentSerializerContext : System.Text.Json.Serialization.JsonSerializerContext { }
-
-[System.Text.Json.Serialization.JsonSourceGenerationOptions(WriteIndented = true)]
-[System.Text.Json.Serialization.JsonSerializable(typeof(LibMatrix.EventTypes.Common.MjolnirShortcodeEventContent))]
-internal partial class MjolnirShortcodeEventContentSerializerContext : System.Text.Json.Serialization.JsonSerializerContext { }
-
-[System.Text.Json.Serialization.JsonSourceGenerationOptions(WriteIndented = true)]
-[System.Text.Json.Serialization.JsonSerializable(typeof(LibMatrix.EventTypes.Common.RoomEmotesEventContent))]
-internal partial class RoomEmotesEventContentSerializerContext : System.Text.Json.Serialization.JsonSerializerContext { }
diff --git a/Utilities/LibMatrix.JsonSerializerContextGenerator/Program.cs b/Utilities/LibMatrix.JsonSerializerContextGenerator/Program.cs
index 76d6357..0c0277b 100644
--- a/Utilities/LibMatrix.JsonSerializerContextGenerator/Program.cs
+++ b/Utilities/LibMatrix.JsonSerializerContextGenerator/Program.cs
@@ -1,8 +1,6 @@
-using System.Reflection;
-using ArcaneLibs;
+using ArcaneLibs;
 using ArcaneLibs.Extensions.Streams;
-using LibMatrix;
-using LibMatrix.Interfaces;
+using LibMatrix.EventTypes;
 
 // string binary = args.Length > 1 ? args[0] : Console.ReadLine()!;
 
@@ -10,13 +8,25 @@ using LibMatrix.Interfaces;
 File.Delete("EventSerializerContexts.g.cs");
 var stream = File.OpenWrite("EventSerializerContexts.g.cs");
 var eventContentTypes = new ClassCollector<EventContent>().ResolveFromAllAccessibleAssemblies();
+
+stream.WriteString("using System.Text.Json.Serialization;\n");
+
+stream.WriteString(string.Join('\n', eventContentTypes.DistinctBy(x => x.Namespace)
+    .Select(x => $"using {x.Namespace};")));
+stream.WriteString("\n\nnamespace LibMatrix.Generated;\n\n[JsonSourceGenerationOptions(WriteIndented = true)]\n");
+
+// stream.WriteString(string.Join('\n', eventContentTypes//.DistinctBy(x => x.Namespace)
+//     .Select(x => $$"""
+//                   [JsonSourceGenerationOptions(WriteIndented = true)]
+//                   [JsonSerializable(typeof({{x.Name}}))]
+//                   internal partial class {{x.Name}}SerializerContext : JsonSerializerContext { }
+//
+//                   """)));
+
 stream.WriteString(string.Join('\n', eventContentTypes//.DistinctBy(x => x.Namespace)
-    .Select(x => $$"""
-                  [System.Text.Json.Serialization.JsonSourceGenerationOptions(WriteIndented = true)]
-                  [System.Text.Json.Serialization.JsonSerializable(typeof({{x.FullName}}))]
-                  internal partial class {{x.Name}}SerializerContext : System.Text.Json.Serialization.JsonSerializerContext { }
+    .Select(x => $"[JsonSerializable(typeof({x.Name}))]")));
 
-                  """)));
+stream.WriteString("\ninternal partial class EventTypeSerializerContext : JsonSerializerContext { }");
 
 await stream.FlushAsync();
 stream.Close();
\ No newline at end of file
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<LibMatrixBotConfiguration>();
 
         services.AddScoped<AuthenticatedHomeserverGeneric>(x => {
-            var config = x.GetService<LibMatrixBotConfiguration>();
-            var hsProvider = x.GetService<HomeserverProviderService>();
+            var config = x.GetService<LibMatrixBotConfiguration>() ?? throw new Exception("No configuration found!");
+            var hsProvider = x.GetService<HomeserverProviderService>() ?? 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<FileStorageProvider> _logger;
-
     public string TargetPath { get; }
 
     /// <summary>
@@ -15,7 +12,6 @@ public class FileStorageProvider : IStorageProvider {
     /// </summary>
     /// <param name="targetPath"></param>
     public FileStorageProvider(string targetPath) {
-        new Logger<FileStorageProvider>(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<EventIdResponse> Reply(RoomMessageEventContent content) => await Room.SendMessageEventAsync(content);
 }