about summary refs log tree commit diff
path: root/ExampleBots/PluralContactBotPoC/Program.cs
blob: b2e041ece8f3af81a44c8950ee90d20fa8db09c6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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<string>() { "matrix" }
};

if(File.Exists("appservice.json"))
    asConfig = JsonSerializer.Deserialize<AppServiceConfiguration>(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<TieredStorageService>(x =>
        new TieredStorageService(
            cacheStorageProvider: new FileStorageProvider("bot_data/cache/"),
            dataStorageProvider: new FileStorageProvider("bot_data/data/")
        )
    );
    services.AddSingleton<PluralContactBotConfiguration>();
    services.AddSingleton<AppServiceConfiguration>();

    services.AddRoryLibMatrixServices();
    services.AddBot(withCommands: true);

    services.AddHostedService<PluralContactBot>();
}).UseConsoleLifetime().Build();

await host.RunAsync();