-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBot.cs
72 lines (61 loc) · 2.43 KB
/
Bot.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
using System;
using System.Threading.Tasks;
using DSharpPlus;
using DSharpPlus.CommandsNext;
using DSharpPlus.Interactivity;
using OtherWorldBot.Services;
using OtherWorldBot.Handlers;
using Microsoft.Extensions.DependencyInjection;
using OtherWorldBot.Entities;
using System.Linq;
using DSharpPlus.Interactivity.Enums;
namespace OtherWorldBot
{
public class Bot
{
public DiscordClient Client { get; set; }
public InteractivityExtension Interactivity { get; set; }
public LogService LogService { get; set; }
public ConfigService ConfigService { get; set; }
public DatabaseService DatabaseService { get; set; }
public ScheduleUpdateService ScheduleUpdateService { get; set; }
public async Task InitAsync()
{
ConfigService = new ConfigService();
var cfg = new DiscordConfiguration
{
Token = ConfigService.BotConfig.Token,
TokenType = TokenType.Bot,
AutoReconnect = true,
LogLevel = ConfigService.BotConfig.LogLevel,
UseInternalLogHandler = true
};
Client = new DiscordClient(cfg);
LogService = new LogService(Client);
ScheduleUpdateService = new ScheduleUpdateService(LogService, ConfigService, DatabaseService);
var deps = new ServiceCollection()
.AddSingleton(ConfigService)
.AddSingleton(LogService)
.AddSingleton(ScheduleUpdateService)
.AddSingleton<DatabaseService>()
.BuildServiceProvider();
Client.UseInteractivity(new InteractivityConfiguration
{
PaginationBehaviour = PaginationBehaviour.Ignore,
Timeout = TimeSpan.FromMinutes(2)
});
Client.UseCommandsNext(new CommandsNextConfiguration
{
StringPrefixes = new[] { ConfigService.BotConfig.CommandPrefix },
EnableDms = true,
Services = deps,
EnableMentionPrefix = true,
EnableDefaultHelp = true
});
new EventsHandler(Client, ConfigService);
new CommandHandler(Client.GetCommandsNext(), ConfigService, LogService);
await Client.ConnectAsync();
await Task.Delay(-1).ConfigureAwait(false);
}
}
}