-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBot.cs
78 lines (60 loc) · 1.91 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
73
74
75
76
77
78
using DSharpPlus;
using DSharpPlus.EventArgs;
using DSharpPlus.SlashCommands;
using Dictobot.Configuration.Structures;
using Dictobot.Commands;
namespace Dictobot
{
public class Bot
{
private static DiscordClient? _client;
private static readonly SlashCommands _slashCommands = new();
private static readonly ScheduleService _scheduleService = new();
private static async Task BotInit()
{
await APIStructure.Shared.Load();
var configuration = new DiscordConfiguration()
{
Intents = DiscordIntents.All,
Token = APIStructure.Data?.Token,
TokenType = TokenType.Bot,
AutoReconnect = true,
};
_client = new(configuration);
_client.Ready += OnClientReady;
_client.GuildAvailable += OnGuildAvailable;
SlashCommandsInit();
await _client!.ConnectAsync();
await DatabaseInit();
await ServicesInit();
}
private static Task OnClientReady(DiscordClient sender, ReadyEventArgs args) => Task.CompletedTask;
private static Task OnGuildAvailable(DiscordClient client, GuildCreateEventArgs args) => Task.CompletedTask;
private static void SlashCommandsInit()
{
var commandConfig = _client.UseSlashCommands();
commandConfig.RegisterCommands<SlashCommands>();
}
private static async Task ScheduleServiceInit()
{
await _scheduleService.SendEmbedMessageAsync(_client!);
}
private static async Task DatabaseInit()
{
await DatabaseSettingsStructure.Shared.Load();
}
private static async Task ServicesInit()
{
await ScheduleServiceInit();
}
private static async Task BotRun()
{
await Task.Delay(Timeout.Infinite);
}
private static async Task Main()
{
await BotInit();
await BotRun();
}
}
}