-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
executable file
·76 lines (63 loc) · 2.23 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
68
69
70
71
72
73
74
75
76
using Discord;
using Discord.WebSocket;
using NLog;
using System.Threading.Tasks;
namespace Kaepora
{
class Program
{
static void Main() => AsyncMain().GetAwaiter().GetResult();
private static Logger _coreLogger = LogManager.GetLogger("Main");
static async Task AsyncMain()
{
_coreLogger.Info("Starting up bot");
_coreLogger.Info("Reading Config");
var config = CoreConfig.ReadConfig();
var client = new DiscordSocketClient();
client.Log += logging;
_coreLogger.Info("Initializing Service Manager");
var serviceDepMap = new ServiceDependencyMap(client);
_coreLogger.Info("Initializing Command Handler");
var cmdHandler = new CommandHandler(client, serviceDepMap);
await cmdHandler.AddAllCommands();
_coreLogger.Info("Beginning Login and Connection to Discord");
await client.LoginAsync(TokenType.Bot, config.Token);
await client.StartAsync();
cmdHandler.StartListening();
await Task.Delay(-1);
}
private static Task logging(LogMessage arg)
{
LogLevel level;
switch (arg.Severity)
{
case LogSeverity.Debug:
level = LogLevel.Trace;
break;
case LogSeverity.Verbose:
level = LogLevel.Debug;
break;
case LogSeverity.Info:
level = LogLevel.Info;
break;
case LogSeverity.Warning:
level = LogLevel.Warn;
break;
case LogSeverity.Error:
level = LogLevel.Error;
break;
case LogSeverity.Critical:
level = LogLevel.Fatal;
break;
default:
level = LogLevel.Off;
break;
}
if (arg.Exception == null)
_coreLogger.Log(level, arg.Message);
else
_coreLogger.Log(level, arg.Exception, arg.Message);
return Task.CompletedTask;
}
}
}