-
Notifications
You must be signed in to change notification settings - Fork 4
/
Core.cs
63 lines (60 loc) · 2.3 KB
/
Core.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
namespace PoE.Bot
{
using Discord;
using Discord.WebSocket;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
using PoE.Bot.Attributes;
using PoE.Bot.Contexts;
using PoE.Bot.Extensions;
using PoE.Bot.Services;
using Qmmands;
using System;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Reflection;
using System.Threading.Tasks;
public static class Core
{
private static async Task Main()
{
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.Build();
var assembly = Assembly.GetEntryAssembly();
var types = assembly.GetTypes().Where(x => x.GetCustomAttributes(typeof(ServiceAttribute), true).Length > 0);
var services = new ServiceCollection()
.AddSingleton(new DiscordSocketClient(new DiscordSocketConfig
{
AlwaysDownloadUsers = true,
LogLevel = LogSeverity.Info,
MessageCacheSize = 100
}))
.AddSingleton(new CommandService(new CommandServiceConfiguration
{
CaseSensitive = false
})
.AddTypeParsers(assembly))
.AddSingleton<HttpClient>()
.AddSingleton(new Random())
.AddServices(types)
.AddLogging(builder =>
{
builder.SetMinimumLevel(LogLevel.Trace);
builder.AddNLog(new NLogProviderOptions
{
CaptureMessageTemplates = true,
CaptureMessageProperties = true
});
})
.AddDbContext<DatabaseContext>(options => options.UseSqlite(configuration.GetConnectionString("Sqlite")), ServiceLifetime.Transient)
.BuildServiceProvider();
await services.GetRequiredService<BotStartService>().InitializeAsync();
}
}
}