3 files changed, 42 insertions, 4 deletions
diff --git a/Utilities/LibMatrix.Utilities.Bot/AppServiceConfiguration.cs b/Utilities/LibMatrix.Utilities.Bot/AppServices/AppServiceConfiguration.cs
index afda89e..2cfcf32 100644
--- a/Utilities/LibMatrix.Utilities.Bot/AppServiceConfiguration.cs
+++ b/Utilities/LibMatrix.Utilities.Bot/AppServices/AppServiceConfiguration.cs
@@ -1,23 +1,47 @@
-namespace LibMatrix.Utilities.Bot;
+using System.Text.Json.Serialization;
+
+namespace LibMatrix.Utilities.Bot.AppServices;
public class AppServiceConfiguration {
+ [JsonPropertyName("id")]
public string Id { get; set; } = null!;
+
+ [JsonPropertyName("url")]
public string? Url { get; set; } = null!;
+
+ [JsonPropertyName("sender_localpart")]
public string SenderLocalpart { get; set; } = null!;
+
+ [JsonPropertyName("as_token")]
public string AppserviceToken { get; set; } = null!;
+
+ [JsonPropertyName("hs_token")]
public string HomeserverToken { get; set; } = null!;
+
+ [JsonPropertyName("protocols")]
public List<string>? Protocols { get; set; } = null!;
+
+ [JsonPropertyName("rate_limited")]
public bool? RateLimited { get; set; } = null!;
+ [JsonPropertyName("namespaces")]
public AppserviceNamespaces Namespaces { get; set; } = null!;
public class AppserviceNamespaces {
+ [JsonPropertyName("users")]
public List<AppserviceNamespace>? Users { get; set; } = null;
+
+ [JsonPropertyName("aliases")]
public List<AppserviceNamespace>? Aliases { get; set; } = null;
+
+ [JsonPropertyName("rooms")]
public List<AppserviceNamespace>? Rooms { get; set; } = null;
public class AppserviceNamespace {
+ [JsonPropertyName("exclusive")]
public bool Exclusive { get; set; }
+
+ [JsonPropertyName("regex")]
public string Regex { get; set; } = null!;
}
}
diff --git a/Utilities/LibMatrix.Utilities.Bot/BotCommandInstaller.cs b/Utilities/LibMatrix.Utilities.Bot/BotCommandInstaller.cs
index 621c1ee..ca6a4d8 100644
--- a/Utilities/LibMatrix.Utilities.Bot/BotCommandInstaller.cs
+++ b/Utilities/LibMatrix.Utilities.Bot/BotCommandInstaller.cs
@@ -1,8 +1,7 @@
using ArcaneLibs;
-using LibMatrix.EventTypes.Spec.State;
using LibMatrix.Homeservers;
-using LibMatrix.Responses;
using LibMatrix.Services;
+using LibMatrix.Utilities.Bot.AppServices;
using LibMatrix.Utilities.Bot.Interfaces;
using LibMatrix.Utilities.Bot.Services;
using Microsoft.Extensions.DependencyInjection;
@@ -22,6 +21,20 @@ public class BotInstaller(IServiceCollection services) {
services.AddScoped<AuthenticatedHomeserverGeneric>(x => {
var config = x.GetService<LibMatrixBotConfiguration>() ?? throw new Exception("No configuration found!");
var hsProvider = x.GetService<HomeserverProviderService>() ?? throw new Exception("No homeserver provider found!");
+
+ if (x.GetService<AppServiceConfiguration>() is AppServiceConfiguration appsvcConfig)
+ config.AccessToken = appsvcConfig.AppserviceToken;
+ else if (Environment.GetEnvironmentVariable("LIBMATRIX_ACCESS_TOKEN_PATH") is string path)
+ config.AccessTokenPath = path;
+
+ if(string.IsNullOrWhiteSpace(config.AccessToken) && string.IsNullOrWhiteSpace(config.AccessTokenPath))
+ throw new Exception("Unable to add bot service without an access token or access token path!");
+
+ if(!string.IsNullOrWhiteSpace(config.AccessTokenPath)) {
+ var token = File.ReadAllText(config.AccessTokenPath);
+ config.AccessToken = token;
+ }
+
var hs = hsProvider.GetAuthenticatedWithToken(config.Homeserver, config.AccessToken).Result;
return hs;
diff --git a/Utilities/LibMatrix.Utilities.Bot/LibMatrixBotConfiguration.cs b/Utilities/LibMatrix.Utilities.Bot/LibMatrixBotConfiguration.cs
index 245442f..728b169 100644
--- a/Utilities/LibMatrix.Utilities.Bot/LibMatrixBotConfiguration.cs
+++ b/Utilities/LibMatrix.Utilities.Bot/LibMatrixBotConfiguration.cs
@@ -6,7 +6,8 @@ namespace LibMatrix.Utilities.Bot;
public class LibMatrixBotConfiguration {
public LibMatrixBotConfiguration(IConfiguration config) => config.GetRequiredSection("LibMatrixBot").Bind(this);
public string Homeserver { get; set; }
- public string AccessToken { get; set; }
+ public string? AccessToken { get; set; }
+ public string? AccessTokenPath { get; set; }
public List<string> Prefixes { get; set; }
public bool MentionPrefix { get; set; }
public string? LogRoom { get; set; }
|