From 6bd02248ccfbcb46960a6f39eaad23888d190eb5 Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Fri, 15 Sep 2023 09:50:45 +0200 Subject: Some refactoring --- ExampleBots/PluralContactBotPoC/Program.cs | 75 ++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 ExampleBots/PluralContactBotPoC/Program.cs (limited to 'ExampleBots/PluralContactBotPoC/Program.cs') diff --git a/ExampleBots/PluralContactBotPoC/Program.cs b/ExampleBots/PluralContactBotPoC/Program.cs new file mode 100644 index 0000000..b2e041e --- /dev/null +++ b/ExampleBots/PluralContactBotPoC/Program.cs @@ -0,0 +1,75 @@ +// See https://aka.ms/new-console-template for more information + +using System.Text.Json; +using System.Text.Json.Serialization; +using ArcaneLibs.Extensions; +using LibMatrix.Services; +using LibMatrix.Utilities.Bot; +using MediaModeratorPoC.Bot; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using PluralContactBotPoC; +using PluralContactBotPoC.Bot; + +Console.WriteLine("Hello, World!"); + +var randomBytes = new byte[32]; +Random.Shared.NextBytes(randomBytes); +var ASToken = Convert.ToBase64String(randomBytes); +Random.Shared.NextBytes(randomBytes); +var HSToken = Convert.ToBase64String(randomBytes); + +var asConfig = new AppServiceConfiguration() { + Id = "plural_contact_bot", + Url = null, + SenderLocalpart = "plural_contact_bot", + AppserviceToken = ASToken, + HomeserverToken = HSToken, + Namespaces = new() { + Users = new() { + new() { + Exclusive = false, + Regex = "@.*" + } + }, + Aliases = new() { + new() { + Exclusive = false, + Regex = "#.*" + } + }, + Rooms = new() { + new() { + Exclusive = false, + Regex = "!.*" + } + } + }, + RateLimited = false, + Protocols = new List() { "matrix" } +}; + +if(File.Exists("appservice.json")) + asConfig = JsonSerializer.Deserialize(File.ReadAllText("appservice.json"))!; + +File.WriteAllText("appservice.yaml", asConfig.ToYaml()); +File.WriteAllText("appservice.json", asConfig.ToJson()); +Environment.Exit(0); + +var host = Host.CreateDefaultBuilder(args).ConfigureServices((_, services) => { + services.AddScoped(x => + new TieredStorageService( + cacheStorageProvider: new FileStorageProvider("bot_data/cache/"), + dataStorageProvider: new FileStorageProvider("bot_data/data/") + ) + ); + services.AddSingleton(); + services.AddSingleton(); + + services.AddRoryLibMatrixServices(); + services.AddBot(withCommands: true); + + services.AddHostedService(); +}).UseConsoleLifetime().Build(); + +await host.RunAsync(); -- cgit 1.4.1