-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
56 lines (46 loc) · 1.88 KB
/
Program.cs
File metadata and controls
56 lines (46 loc) · 1.88 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
47
48
49
50
51
52
53
54
55
56
using DSharpPlus.Extensions;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using CalamityAssetBot;
using CalamityAssetBot.Hosting;
using CalamityAssetBot.Logging;
using CalamityAssetBot.Utils;
using DSharpPlus.Commands;
using DSharpPlus.Commands.Processors.SlashCommands;
//----------------------//
//----------------------//
var workingDirectory = Directory.CreateDirectory("BotFiles");
Directory.SetCurrentDirectory(workingDirectory.FullName);
AppDomain.CurrentDomain.UnhandledException += (sender, exception) =>
{
DiscordLogger.Writer.Close();
File.WriteAllText("Crash.txt", exception.ExceptionObject.ToString());
};
var builder = new HostApplicationBuilder();
builder.Services.AddHostedSingleton<DiscordBotService>();
builder.Services.AddHostedSingleton<Cache>();
builder.Services.AddDiscordClient(DiscordBotService.Token, DiscordBotService.Intents);
builder.Services.RegisterEventHandlers();
builder.Services.AddAsyncTimers();
builder.Services.AddCommandsExtension(
(_, commands) => {
commands.AddCheck<DiscordBotService.OneCommandAtATime>();
commands.AddProcessor<SlashCommandProcessor>();
commands.AddCommands(typeof(DiscordBotService).Assembly);
commands.CommandExecuted += async (_, args) => await DiscordBotService.OneCommandAtATime.CompleteCommandAsync();
commands.CommandErrored += async (_, args) => await DiscordBotService.OneCommandAtATime.CompleteCommandAsync();
},
new CommandsConfiguration() {
RegisterDefaultCommandProcessors = false,
UseDefaultCommandErrorHandler = false
}
);
builder.Services.AddLogging(logger =>
{
logger.ClearProviders();
logger.AddProvider(new DiscordLoggerProvider());
logger.SetMinimumLevel(LogLevel.Trace);
});
var host = builder.Build();
host.Run();