feat: add channel create responder and redis webhook cache
This commit is contained in:
parent
99c1587e7b
commit
e86b37ce2a
11 changed files with 201 additions and 10 deletions
|
|
@ -3,6 +3,7 @@ using Catalogger.Backend.Bot.Responders;
|
|||
using Catalogger.Backend.Cache;
|
||||
using Catalogger.Backend.Database;
|
||||
using Catalogger.Backend.Database.Queries;
|
||||
using Catalogger.Backend.Database.Redis;
|
||||
using Catalogger.Backend.Services;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NodaTime;
|
||||
|
|
@ -21,10 +22,8 @@ public static class StartupExtensions
|
|||
/// <summary>
|
||||
/// Adds Serilog to this service collection. This method also initializes Serilog, so it should be called as early as possible, before any log calls.
|
||||
/// </summary>
|
||||
public static WebApplicationBuilder AddSerilog(this WebApplicationBuilder builder)
|
||||
public static WebApplicationBuilder AddSerilog(this WebApplicationBuilder builder, Config config)
|
||||
{
|
||||
var config = builder.Configuration.Get<Config>() ?? new();
|
||||
|
||||
var logCfg = new LoggerConfiguration()
|
||||
.Enrich.FromLogContext()
|
||||
.MinimumLevel.Is(config.Logging.LogEventLevel)
|
||||
|
|
@ -67,10 +66,10 @@ public static class StartupExtensions
|
|||
public static IServiceCollection AddCustomServices(this IServiceCollection services) => services
|
||||
.AddSingleton<IClock>(SystemClock.Instance)
|
||||
.AddSingleton<GuildCacheService>()
|
||||
.AddSingleton<RoleCacheService>()
|
||||
.AddSingleton<ChannelCacheService>()
|
||||
.AddSingleton<UserCacheService>()
|
||||
.AddSingleton<PluralkitApiService>()
|
||||
.AddSingleton<IWebhookCache, InMemoryWebhookCache>()
|
||||
.AddScoped<IEncryptionService, EncryptionService>()
|
||||
.AddScoped<MessageRepository>()
|
||||
.AddSingleton<WebhookExecutorService>()
|
||||
|
|
@ -78,6 +77,17 @@ public static class StartupExtensions
|
|||
.AddSingleton(InMemoryDataService<Snowflake, ChannelCommandData>.Instance)
|
||||
.AddHostedService<MetricsCollectionService>();
|
||||
|
||||
public static IServiceCollection MaybeAddRedisCaches(this IServiceCollection services, Config config)
|
||||
{
|
||||
if (config.Database.Redis == null)
|
||||
{
|
||||
return services.AddSingleton<IWebhookCache, InMemoryWebhookCache>();
|
||||
}
|
||||
|
||||
return services.AddSingleton<RedisService>()
|
||||
.AddScoped<IWebhookCache, RedisWebhookCache>();
|
||||
}
|
||||
|
||||
public static async Task Initialize(this WebApplication app)
|
||||
{
|
||||
await using var scope = app.Services.CreateAsyncScope();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue