about summary refs log tree commit diff
path: root/Program.cs
blob: 67403c140c36a617d2b5cedac59068f7de53eccd (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
// See https://aka.ms/new-console-template for more information

using LibMatrix.Services;
using LibMatrix.Utilities.Bot;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using ModerationBot;
using ModerationBot.Services;

Console.WriteLine("Hello, World!");

var builder = Host.CreateDefaultBuilder(args);

builder.ConfigureHostOptions(host => {
    host.ServicesStartConcurrently = true;
    host.ServicesStopConcurrently = true;
    host.ShutdownTimeout = TimeSpan.FromSeconds(5);
});

if (Environment.GetEnvironmentVariable("MODERATIONBOT_APPSETTINGS_PATH") is string path)
    builder.ConfigureAppConfiguration(x => x.AddJsonFile(path));

var host = builder.ConfigureServices((_, services) => {
    services.AddScoped<TieredStorageService>(x =>
        new TieredStorageService(
            cacheStorageProvider: new FileStorageProvider("bot_data/cache/"),
            dataStorageProvider: new FileStorageProvider("bot_data/data/")
        )
    );
    services.AddSingleton<ModerationBotConfiguration>();

    services.AddRoryLibMatrixServices();
    services.AddMatrixBot().AddCommandHandler().DiscoverAllCommands();

    services.AddSingleton<PolicyEngine>();
    services.AddSingleton<ModerationBotRoomProvider>();

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

await host.RunAsync();