-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathProgram.cs
67 lines (59 loc) · 2.17 KB
/
Program.cs
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
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Discord;
using Discord.Commands;
using Discord.WebSocket;
using TurtleBot.Services;
namespace TurtleBot
{
class Program
{
static void Main(string[] args)
=> new Program().MainAsync().GetAwaiter().GetResult();
private DiscordSocketClient _client;
private IConfiguration _config;
public async Task MainAsync()
{
_client = new DiscordSocketClient(new DiscordSocketConfig { AlwaysDownloadUsers = true });
_config = BuildConfig();
var services = ConfigureServices();
services.GetRequiredService<LogService>();
services.GetRequiredService<StarService>(); // Mark as required so the reaction event handlers are loaded
await services.GetRequiredService<CommandHandlingService>().InitializeAsync(services);
await _client.LoginAsync(TokenType.Bot, _config["token"]);
await _client.StartAsync();
await Task.Delay(-1);
}
private IServiceProvider ConfigureServices()
{
return new ServiceCollection()
// Base
.AddSingleton(_client)
.AddSingleton<CommandService>()
.AddSingleton<CommandHandlingService>()
// Database
.AddSingleton<DatabaseService>()
// Tags
.AddSingleton<TagService>()
//Stars
.AddSingleton<StarService>()
// Logging
.AddLogging()
.AddSingleton<LogService>()
// Extra
.AddSingleton(_config)
// Add additional services here...
.BuildServiceProvider();
}
private IConfiguration BuildConfig()
{
return new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("config.json")
.Build();
}
}
}