/ Program.cs
Program.cs
 1  using _5uhr;
 2  using Microsoft.AspNetCore.Identity;
 3  using Microsoft.EntityFrameworkCore;
 4  using _5uhr.Data;
 5  using Discord;
 6  using Discord.Interactions;
 7  using Discord.Rest;
 8  using Discord.WebSocket;
 9  
10  var builder = WebApplication.CreateBuilder(args);
11  
12  // Add services to the container.
13  var connectionString = builder.Configuration.GetConnectionString("DefaultConnection") ?? throw new InvalidOperationException("Connection string 'DefaultConnection' not found.");
14  builder.Services.AddDbContext<ApplicationDbContext>(options =>
15      options.UseNpgsql(connectionString));
16  builder.Services.AddDatabaseDeveloperPageExceptionFilter();
17  
18  builder.Services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
19      .AddEntityFrameworkStores<ApplicationDbContext>();
20  builder.Services.AddRazorPages();
21  
22  builder.Services
23      .AddSingleton(new DiscordSocketConfig()
24      {
25          GatewayIntents = GatewayIntents.AllUnprivileged,
26      })
27      .AddSingleton<DiscordSocketClient>()
28      .AddTransient<IRestClientProvider>(s => s.GetRequiredService<DiscordSocketClient>())
29      .AddHostedService<DiscordBotService>()
30      .AddSingleton(new InteractionServiceConfig()
31      {
32          UseCompiledLambda = true, // We use a lot of modals
33          DefaultRunMode = RunMode.Async,
34      })
35      .AddSingleton<InteractionService>()
36      .AddTransient<RegistrationModule>()
37      .AddSingleton<InfoService>()
38      .AddHostedService<PeriodicInfo>();
39  
40  var app = builder.Build();
41  
42  // Configure the HTTP request pipeline.
43  if (app.Environment.IsDevelopment())
44  {
45      app.UseMigrationsEndPoint();
46  }
47  else
48  {
49      app.UseExceptionHandler("/Error");
50      // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
51      app.UseHsts();
52  }
53  
54  app.UseHttpsRedirection();
55  
56  app.UseRouting();
57  
58  app.UseAuthorization();
59  
60  app.MapStaticAssets();
61  app.MapRazorPages()
62     .WithStaticAssets();
63  
64  app.Run();