-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
86 lines (71 loc) · 2.43 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
77
78
79
80
81
82
83
84
85
86
using System;
using System.Threading;
using System.Threading.Tasks;
using Discord;
using Discord.Interactions;
using Discord.WebSocket;
using Natsirt.Modules;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace Natsirt;
public class Program
{
private readonly IConfiguration _configuration;
private readonly IServiceProvider _services;
private readonly DiscordSocketConfig _socketConfig = new()
{
GatewayIntents = GatewayIntents.AllUnprivileged | GatewayIntents.GuildMembers | GatewayIntents.MessageContent | GatewayIntents.GuildMessages | GatewayIntents.GuildVoiceStates,
AlwaysDownloadUsers = true,
};
public Program()
{
_configuration = new ConfigurationBuilder()
.AddEnvironmentVariables("DC_")
.Build();
_services = new ServiceCollection()
.AddSingleton(_configuration)
.AddSingleton(_socketConfig)
.AddSingleton<DiscordSocketClient>()
.AddSingleton<AdminAPI>()
.AddSingleton<NatsirtCave>()
.AddSingleton<NatsirtAI>()
.AddSingleton<VCGroups>()
.AddSingleton<TicketLogs>()
.AddSingleton(x => new InteractionService(x.GetRequiredService<DiscordSocketClient>()))
.AddSingleton<InteractionHandler>()
.BuildServiceProvider();
}
private static void Main(string[] args)
{
new Program().RunAsync()
.GetAwaiter()
.GetResult();
}
public async Task RunAsync()
{
var client = _services.GetRequiredService<DiscordSocketClient>();
client.Log += LogAsync;
await _services.GetRequiredService<InteractionHandler>()
.InitializeAsync();
await _services.GetRequiredService<VCGroups>()
.InitializeAsync();
await _services.GetRequiredService<TicketLogs>()
.InitializeAsync();
await client.LoginAsync(TokenType.Bot, _configuration["token"]);
await client.StartAsync();
await client.SetActivityAsync(new StreamingGame("tsmp's events", "https://www.twitch.tv/twisttaan"));
await Task.Delay(Timeout.Infinite);
}
private async Task LogAsync(LogMessage message)
{
Console.WriteLine(message.ToString());
}
public static bool IsDebug()
{
#if DEBUG
return true;
#else
return false;
#endif
}
}