-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStartUp.cs
More file actions
73 lines (63 loc) · 2.33 KB
/
StartUp.cs
File metadata and controls
73 lines (63 loc) · 2.33 KB
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
using System;
using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using Discord.WebSocket;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using BorisGangBot_Mk2.Services;
using BorisGangBot_Mk2.Services.GuildInfo;
using BorisGangBot_Mk2.Services.LiveStreamMono;
namespace BorisGangBot_Mk2
{
class StartUp
{
private IConfigurationRoot Configuration { get; }
public StartUp(string[] args)
{
var builder = new ConfigurationBuilder()
.SetBasePath(AppContext.BaseDirectory)
.AddYamlFile("_config.yml");
Configuration = builder.Build();
}
public static async Task RunAsync(string[] args)
{
var startup = new StartUp(args);
await startup.RunAsync();
}
private async Task RunAsync()
{
var services = new ServiceCollection();
ConfigureServices(services);
var provider = services.BuildServiceProvider();
provider.GetRequiredService<LoggingService>();
provider.GetRequiredService<CommandHandler>();
provider.GetRequiredService<GuildJoinedService>();
provider.GetRequiredService<StreamMonoService>();
provider.GetRequiredService<GuildInfoService>();
await provider.GetRequiredService<StartUpService>().StartAsync();
await Task.Delay(-1);
}
private void ConfigureServices(IServiceCollection services)
{
services.AddSingleton(new DiscordSocketClient(new DiscordSocketConfig
{
LogLevel = LogSeverity.Verbose,
MessageCacheSize = 100
}))
.AddSingleton(new CommandService(new CommandServiceConfig
{
LogLevel = LogSeverity.Verbose,
DefaultRunMode = RunMode.Async
}))
.AddSingleton<CommandHandler>()
.AddSingleton<StartUpService>()
.AddSingleton<LoggingService>()
.AddSingleton<GuildJoinedService>()
.AddSingleton<StreamMonoService>()
.AddSingleton<GuildInfoService>()
.AddSingleton<Random>()
.AddSingleton(Configuration);
}
}
}