2025-05-15 13:13:37 -05:00
|
|
|
using Microsoft.Extensions.Options;
|
2025-05-07 22:59:38 -05:00
|
|
|
|
|
|
|
|
var builder = Host.CreateApplicationBuilder(args);
|
2025-05-15 13:13:37 -05:00
|
|
|
|
|
|
|
|
builder.Services.Configure<HostOptions>(static options => options.ShutdownTimeout = TimeSpan.FromSeconds(30));
|
|
|
|
|
|
|
|
|
|
builder.Services.AddOptions<DiscordClientOptions>()
|
|
|
|
|
.BindConfiguration(nameof(DiscordClientOptions));
|
|
|
|
|
|
|
|
|
|
builder.Services.AddSingleton(static sp =>
|
|
|
|
|
{
|
|
|
|
|
var discordOptions = sp.GetRequiredService<IOptions<DiscordClientOptions>>().Value;
|
|
|
|
|
return discordOptions;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
builder.Services.AddSingleton<IWebSocketFactory, WebSocketFactory>();
|
|
|
|
|
builder.Services.AddSingleton(TimeProvider.System);
|
|
|
|
|
|
|
|
|
|
builder.Services
|
|
|
|
|
.AddHttpClient<IDiscordRestClient, DiscordRestClient>(static (sp, c) =>
|
|
|
|
|
{
|
|
|
|
|
var discordOptions = sp.GetRequiredService<DiscordClientOptions>();
|
|
|
|
|
c.BaseAddress = new Uri(discordOptions.ApiUrl);
|
|
|
|
|
c.DefaultRequestHeaders.Authorization = new("Bot", discordOptions.AppToken);
|
|
|
|
|
})
|
|
|
|
|
.AddStandardResilienceHandler();
|
|
|
|
|
|
2025-05-15 22:52:51 -05:00
|
|
|
// TODO: Create an extension method that allows adding
|
|
|
|
|
// the discord gateway client and allows me to configure
|
|
|
|
|
// event handlers
|
2025-05-15 13:13:37 -05:00
|
|
|
builder.Services.AddSingleton<IDiscordGatewayClient, DiscordGatewayClient>();
|
2025-05-15 22:52:51 -05:00
|
|
|
|
2025-05-07 22:59:38 -05:00
|
|
|
builder.Services.AddHostedService<Worker>();
|
|
|
|
|
|
|
|
|
|
var host = builder.Build();
|
2025-05-07 23:54:46 -05:00
|
|
|
await host.RunAsync();
|