feat: store timeouts in database and log them ending

we have to do this because discord doesn't notify us when a timeout
ends naturally, only when a moderator removes it early.
This commit is contained in:
sam 2024-11-05 22:22:12 +01:00
parent f0fcfd7bd3
commit e6d68338db
Signed by: sam
GPG key ID: 5F3C3C1B3166639D
7 changed files with 249 additions and 1 deletions

View file

@ -108,6 +108,7 @@ public static class StartupExtensions
.AddScoped<GuildRepository>()
.AddScoped<InviteRepository>()
.AddScoped<WatchlistRepository>()
.AddScoped<TimeoutRepository>()
.AddSingleton<GuildCache>()
.AddSingleton<RoleCache>()
.AddSingleton<ChannelCache>()
@ -117,12 +118,13 @@ public static class StartupExtensions
.AddSingleton<PluralkitApiService>()
.AddSingleton<NewsService>()
.AddScoped<IEncryptionService, EncryptionService>()
.AddSingleton<TimeoutService>()
.AddSingleton<MetricsCollectionService>()
.AddSingleton<WebhookExecutorService>()
.AddSingleton<PkMessageHandler>()
.AddSingleton(InMemoryDataService<Snowflake, ChannelCommandData>.Instance)
.AddSingleton<GuildFetchService>()
.AddTransient<PermissionResolverService>()
.AddSingleton<GuildFetchService>()
// Background services
// GuildFetchService is added as a separate singleton as it's also injected into other services.
.AddHostedService(serviceProvider =>
@ -207,6 +209,7 @@ public static class StartupExtensions
var config = scope.ServiceProvider.GetRequiredService<Config>();
var slashService = scope.ServiceProvider.GetRequiredService<SlashService>();
var timeoutService = scope.ServiceProvider.GetRequiredService<TimeoutService>();
if (config.Discord.TestMode)
logger.Warning(
@ -249,6 +252,9 @@ public static class StartupExtensions
logger.Information(
"Not syncing slash commands, Discord.SyncCommands is false or unset"
);
// Initialize the timeout service by loading all the timeouts currently in the database.
await timeoutService.InitializeAsync();
}
public static void MaybeAddDashboard(this WebApplication app)