diff --git a/src/Miha.Discord/Miha.Discord.csproj b/src/Miha.Discord/Miha.Discord.csproj
index 9334370..f89e1f6 100644
--- a/src/Miha.Discord/Miha.Discord.csproj
+++ b/src/Miha.Discord/Miha.Discord.csproj
@@ -9,11 +9,11 @@
-
-
+
+
-
+
diff --git a/src/Miha.Logic/Miha.Logic.csproj b/src/Miha.Logic/Miha.Logic.csproj
index 453b095..e360038 100644
--- a/src/Miha.Logic/Miha.Logic.csproj
+++ b/src/Miha.Logic/Miha.Logic.csproj
@@ -8,8 +8,8 @@
-
-
+
+
diff --git a/src/Miha.Redis/Miha.Redis.csproj b/src/Miha.Redis/Miha.Redis.csproj
index 8f23898..67b4255 100644
--- a/src/Miha.Redis/Miha.Redis.csproj
+++ b/src/Miha.Redis/Miha.Redis.csproj
@@ -8,9 +8,9 @@
-
-
-
+
+
+
diff --git a/src/Miha.Shared/Miha.Shared.csproj b/src/Miha.Shared/Miha.Shared.csproj
index 3a0e0c2..e436505 100644
--- a/src/Miha.Shared/Miha.Shared.csproj
+++ b/src/Miha.Shared/Miha.Shared.csproj
@@ -8,7 +8,7 @@
-
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
@@ -16,15 +16,15 @@
-
-
-
-
+
+
+
+
-
-
-
+
+
+
diff --git a/src/Miha/Program.cs b/src/Miha/Program.cs
index a636283..aba6557 100644
--- a/src/Miha/Program.cs
+++ b/src/Miha/Program.cs
@@ -1,7 +1,4 @@
-using Discord;
-using Discord.Addons.Hosting;
-using Discord.WebSocket;
-using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options;
@@ -30,7 +27,7 @@
builder.AddJsonFile("appsettings.edge.json", optional: true, reloadOnChange: false);
}
- // Disable ReloadOnChange for all sources, we don't intend to support this
+ // Disable ReloadOnChange for all sources, we don't intend to support this,
// and it creates a lot of inotify issues on docker hosts running on linux
foreach (var s in builder.Sources)
{
@@ -45,53 +42,16 @@
.Enrich.FromLogContext()
.Enrich.WithExceptionDetails()
.WriteTo.Console(new CompactJsonFormatter()))
- .ConfigureDiscordHost((context, config) =>
- {
- var discordOptions = context.Configuration.GetSection(DiscordOptions.Section).Get();
-
- if (string.IsNullOrEmpty(discordOptions?.Token))
- {
- throw new ArgumentNullException(nameof(discordOptions.Token), "Discord token cannot be empty or null");
- }
-
- if (discordOptions.Guild is null)
- {
- throw new ArgumentNullException(nameof(discordOptions.Guild), "Need a target guild id, Miha does not support multi-guilds yet");
- }
-
- config.SocketConfig = new DiscordSocketConfig
- {
- LogLevel = LogSeverity.Verbose,
- LogGatewayIntentWarnings = true,
- AlwaysDownloadUsers = true,
- GatewayIntents = GatewayIntents.GuildScheduledEvents
- | GatewayIntents.DirectMessageTyping
- | GatewayIntents.DirectMessageReactions
- | GatewayIntents.DirectMessages
- | GatewayIntents.GuildMessageTyping
- | GatewayIntents.GuildMessageReactions
- | GatewayIntents.GuildMessages
- | GatewayIntents.GuildVoiceStates
- | GatewayIntents.Guilds
- | GatewayIntents.GuildMembers
- };
-
- config.Token = discordOptions.Token;
- })
- .UseInteractionService((_, config) =>
- {
- config.LogLevel = LogSeverity.Verbose;
- config.UseCompiledLambda = true;
- })
.ConfigureServices(Startup.ConfigureServices)
.Build();
var discordOptions = host.Services.GetRequiredService>();
var seedService = host.Services.GetRequiredService();
-
+
await seedService.SeedGuildAsync(discordOptions.Value.Guild);
-
+
await host.RunAsync();
+
return 0;
}
catch (Exception ex)
diff --git a/src/Miha/Startup.cs b/src/Miha/Startup.cs
index bafff1a..fe83fb8 100644
--- a/src/Miha/Startup.cs
+++ b/src/Miha/Startup.cs
@@ -1,6 +1,10 @@
-using Microsoft.Extensions.Configuration;
+using Discord;
+using Discord.Addons.Hosting;
+using Discord.WebSocket;
+using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
+using Microsoft.Extensions.Options;
using Miha.Logic;
using Miha.Redis;
using Miha.Discord;
@@ -31,6 +35,50 @@ public static void ConfigureServices(HostBuilderContext context, IServiceCollect
.AddDiscordHostedServices()
.AddDiscordMessageBus();
+ services
+ .AddDiscordHost((config, provider) =>
+ {
+ var discordOptions = provider.GetRequiredService>().Value;
+
+ if (string.IsNullOrEmpty(discordOptions.Token))
+ {
+ throw new ArgumentNullException(nameof(discordOptions.Token),
+ "Discord token cannot be empty or null");
+ }
+
+ if (discordOptions.Guild is null)
+ {
+ throw new ArgumentNullException(nameof(discordOptions.Guild),
+ "Need a target guild id, Miha does not support multi-guilds yet");
+ }
+
+ config.SocketConfig = new DiscordSocketConfig
+ {
+ LogLevel = LogSeverity.Verbose,
+ LogGatewayIntentWarnings = true,
+ AlwaysDownloadUsers = true,
+ GatewayIntents = GatewayIntents.GuildScheduledEvents
+ | GatewayIntents.DirectMessageTyping
+ | GatewayIntents.DirectMessageReactions
+ | GatewayIntents.DirectMessages
+ | GatewayIntents.GuildMessageTyping
+ | GatewayIntents.GuildMessageReactions
+ | GatewayIntents.GuildMessages
+ | GatewayIntents.GuildVoiceStates
+ | GatewayIntents.Guilds
+ | GatewayIntents.GuildMembers
+ };
+
+ config.Token = discordOptions.Token;
+ });
+
+ services
+ .AddInteractionService((config, _) =>
+ {
+ config.LogLevel = LogSeverity.Verbose;
+ config.UseCompiledLambda = true;
+ });
+
services
.AddLogicServices()
.AddBackgroundServices();