Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions src/Miki/MikiBotApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,23 @@ public override async Task ConfigureAsync(ServiceCollection serviceCollection)
serviceCollection.AddSingleton<IApiClient>(
s => new DiscordApiClient(s.GetService<Config>().Token, s.GetService<ICacheClient>()));

if (!string.IsNullOrEmpty(configuration.Configuration.RedisConnectionString))
{
serviceCollection.AddSingleton(
new RedisConnectionPool(configuration.Configuration.RedisConnectionString));

serviceCollection.AddTransient(
x => x.GetRequiredService<RedisConnectionPool>().Get());

serviceCollection.AddTransient<ICacheClient, StackExchangeCacheClient>();
serviceCollection.AddTransient<IExtendedCacheClient, StackExchangeCacheClient>();
}
else
{
serviceCollection.AddSingleton<ICacheClient, InMemoryCacheClient>();
serviceCollection.AddSingleton<IExtendedCacheClient, InMemoryCacheClient>();
}

if(configuration.IsSelfHosted)
{
serviceCollection.AddSingleton<IGateway>(
Expand All @@ -167,10 +184,7 @@ public override async Task ConfigureAsync(ServiceCollection serviceCollection)
Token = configuration.Configuration.Token,
AllowNonDispatchEvents = true,
Intents = GatewayIntents.AllDefault | GatewayIntents.GuildMembers
}));

serviceCollection.AddSingleton<ICacheClient, InMemoryCacheClient>();
serviceCollection.AddSingleton<IExtendedCacheClient, InMemoryCacheClient>();
}));

var splitConfig = new ConfigurationOptions
{
Expand Down Expand Up @@ -229,15 +243,11 @@ public override async Task ConfigureAsync(ServiceCollection serviceCollection)

serviceCollection.AddSingleton<IGateway>(consumer);

serviceCollection.AddSingleton(
new RedisConnectionPool(configuration.Configuration.RedisConnectionString));

serviceCollection.AddTransient(
x => x.GetRequiredService<RedisConnectionPool>().Get());

serviceCollection.AddTransient<ICacheClient, StackExchangeCacheClient>();
serviceCollection.AddTransient<IExtendedCacheClient, StackExchangeCacheClient>();

if (!string.IsNullOrEmpty(configuration.Configuration.RedisConnectionString))
{
Log.Warning("Self-host is disabled but Redis wasn't configured. Miki is running on in-memory cache!");
}

ISplitClient client = null;
if(!string.IsNullOrEmpty(configuration.Configuration.OptionalValues?.SplitioSdkKey))
{
Expand Down