-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
46 lines (44 loc) · 2.36 KB
/
Program.cs
File metadata and controls
46 lines (44 loc) · 2.36 KB
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
using Discord;
using Discord.Interactions;
using Discord.WebSocket;
using Finder.Bot.Database;
using Microsoft.Extensions.DependencyInjection;
using Finder.Bot.Modules;
using Finder.Bot.Handlers;
using Finder.Bot.Modules.Addons;
using Finder.Bot.Modules.Helpers;
using Finder.Bot.Repositories;
using Microsoft.EntityFrameworkCore;
namespace Finder.Bot;
class Program {
static void Main() => RunAsync().GetAwaiter().GetResult();
static async Task RunAsync() {
await using ServiceProvider services = ConfigureServices();
DiscordShardedClient client = services.GetRequiredService<DiscordShardedClient>();
InteractionService commands = services.GetRequiredService<InteractionService>();
CommandHandler handler = services.GetRequiredService<CommandHandler>();
await handler.Initialize();
client.Log += LoggingService.LogAsync;
commands.Log += LoggingService.LogAsync;
// CountdownTimer.StartTimer(client, services.GetRequiredService<IUnitOfWork>());
// UnBanMuteTimer.StartTimer(client, services.GetRequiredService<IUnitOfWork>());
client.ReactionAdded += TicTacToeModule.OnReactionAddedEvent;
client.ReactionAdded += new ModerationModule(services.GetRequiredService<IUnitOfWork>()).OnReactionAddedEvent;
client.ButtonExecuted += new PollModule(services.GetRequiredService<IUnitOfWork>()).OnButtonExecutedEvent;
client.ButtonExecuted += new TicketingModule.TicketsModule(services.GetRequiredService<IUnitOfWork>()).OnButtonExecutedEvent;
client.MessageReceived += new LevelingModule(services.GetRequiredService<IUnitOfWork>()).OnMessageReceivedEvent;
await client.LoginAsync(TokenType.Bot, Environment.GetEnvironmentVariable("BOT_TOKEN"));
await client.StartAsync();
await Task.Delay(Timeout.Infinite);
}
private static ServiceProvider ConfigureServices() {
return new ServiceCollection()
.AddDbContext<ApplicationContext>(options => options.UseNpgsql(Environment.GetEnvironmentVariable("DB_CONNECTION_STRING")!), ServiceLifetime.Transient)
.AddSingleton<DiscordShardedClient>()
.AddSingleton<InteractionService>()
.AddSingleton<CommandHandler>()
.AddTransient(typeof(IRepository<>), typeof(Repository<>))
.AddTransient<IUnitOfWork, UnitOfWork>()
.BuildServiceProvider();
}
}