Skip to content

Commit

Permalink
Use the new pattern everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
Sella-GH committed Dec 19, 2024
1 parent 8a3ced1 commit af3c70e
Show file tree
Hide file tree
Showing 19 changed files with 123 additions and 161 deletions.
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<PropertyGroup>
<AnalysisLevel>latest-all</AnalysisLevel>
<Configurations>Debug;Release;Docker;Docker-debug</Configurations>
<EnableConfigurationBindingGenerator>true</EnableConfigurationBindingGenerator>
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<ImplicitUsings>disable</ImplicitUsings>
Expand Down
44 changes: 23 additions & 21 deletions src/AzzyBot.Bot/Extensions/IServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,20 @@ public static class IServiceCollectionExtensions
public static void AzzyBotServices(this IServiceCollection services, bool isDev, bool isDocker, int logDays = 7)
{
IServiceProvider serviceProvider = services.BuildServiceProvider();
AzzyBotSettings settings = serviceProvider.GetRequiredService<AzzyBotSettings>();
DatabaseSettings dbSettings = serviceProvider.GetRequiredService<IOptions<DatabaseSettings>>().Value;
AzzyBotSettings botSettings = serviceProvider.GetRequiredService<IOptions<AzzyBotSettings>>().Value;
MusicStreamingSettings musicSettings = serviceProvider.GetRequiredService<IOptions<MusicStreamingSettings>>().Value;

// Need to register as Singleton first
// Otherwise DI doesn't work properly
services.AddSingleton<CoreServiceHost>();
services.AddHostedService(static s => s.GetRequiredService<CoreServiceHost>());

// Register the database services
services.AzzyBotDataServices(isDev, settings.Database!.EncryptionKey, settings.Database.Host, settings.Database.Port, settings.Database.User, settings.Database.Password, settings.Database.DatabaseName);
services.AzzyBotDataServices(isDev, dbSettings.EncryptionKey, dbSettings.Host, dbSettings.Port, dbSettings.User, dbSettings.Password, dbSettings.DatabaseName);

services.DiscordClient(settings.BotToken);
services.DiscordClientCommands(settings);
services.DiscordClient(botSettings.BotToken);
services.DiscordClientCommands(botSettings);
services.DiscordClientInteractivity();

services.AddSingleton<DiscordBotService>();
Expand All @@ -70,23 +72,23 @@ public static void AzzyBotServices(this IServiceCollection services, bool isDev,
services.ConfigureLavalink(config =>
{
Uri baseAddress = (isDocker) ? new("http://AzzyBot-Ms:2333") : new("http://localhost:2333");
if (settings.MusicStreaming is not null)
if (musicSettings is not null)
{
if (!string.IsNullOrWhiteSpace(settings.MusicStreaming.LavalinkHost) && settings.MusicStreaming.LavalinkPort is not 0)
if (!string.IsNullOrWhiteSpace(musicSettings.LavalinkHost) && musicSettings.LavalinkPort is not 0)
{
baseAddress = new($"http://{settings.MusicStreaming.LavalinkHost}:{settings.MusicStreaming.LavalinkPort}");
baseAddress = new($"http://{musicSettings.LavalinkHost}:{musicSettings.LavalinkPort}");

Check warning on line 79 in src/AzzyBot.Bot/Extensions/IServiceCollectionExtensions.cs

View workflow job for this annotation

GitHub Actions / AppScan CodeSweep #1

Open communications scheme detected

Vulnerability: Communications.Unencrypted [Severity: Low]
Raw output
{"file":"IServiceCollectionExtensions.cs","filePath":"src/AzzyBot.Bot/Extensions/IServiceCollectionExtensions.cs","lineNumber":79,"columnNumber":0,"language":"C#","vulnName":"Open communications scheme detected","vulnType":"Communications.Unencrypted","ruleName":"com.hcl.appscan.scanner.csharp.rules.OpenCommunicationCsharp","context":"\"http://{musicSettings.LavalinkHost}:{musicSettings.LavalinkPort}\"","severity":2,"codeFixes":[{"description":"Use secure URI scheme","name":"com.ouncelabs.languagelite.common.rules.fix.SecureCommFix"}],"hashValues":{"0":1196901791,"1":1196901791,"2":-530785606,"3":-530785606,"4":-806336904,"5":-806336904}}

Check warning on line 79 in src/AzzyBot.Bot/Extensions/IServiceCollectionExtensions.cs

View workflow job for this annotation

GitHub Actions / AppScan CodeSweep #2

Open communication detected in Xamarin

Vulnerability: Communications.Unencrypted [Severity: Low]
Raw output
{"file":"IServiceCollectionExtensions.cs","filePath":"src/AzzyBot.Bot/Extensions/IServiceCollectionExtensions.cs","lineNumber":79,"columnNumber":0,"language":"Xamarin","vulnName":"Open communication detected in Xamarin","vulnType":"Communications.Unencrypted","ruleName":"com.hcl.appscan.scanner.xamarin.rules.OpenCommunicationXamarin","context":"\"http://{musicSettings.LavalinkHost}:{musicSettings.LavalinkPort}\"","severity":2,"codeFixes":[{"description":"Use secure URI scheme","name":"com.ouncelabs.languagelite.common.rules.fix.SecureCommFix"}],"hashValues":{"0":1196901791,"1":1196901791,"2":-530785606,"3":-530785606,"4":74171015,"5":74171015}}
}
else if (!string.IsNullOrWhiteSpace(settings.MusicStreaming.LavalinkHost) && settings.MusicStreaming.LavalinkPort is 0)
else if (!string.IsNullOrWhiteSpace(musicSettings.LavalinkHost) && musicSettings.LavalinkPort is 0)
{
baseAddress = new($"http://{settings.MusicStreaming.LavalinkHost}:2333");
baseAddress = new($"http://{musicSettings.LavalinkHost}:2333");

Check warning on line 83 in src/AzzyBot.Bot/Extensions/IServiceCollectionExtensions.cs

View workflow job for this annotation

GitHub Actions / AppScan CodeSweep #1

Open communications scheme detected

Vulnerability: Communications.Unencrypted [Severity: Low]
Raw output
{"file":"IServiceCollectionExtensions.cs","filePath":"src/AzzyBot.Bot/Extensions/IServiceCollectionExtensions.cs","lineNumber":83,"columnNumber":0,"language":"C#","vulnName":"Open communications scheme detected","vulnType":"Communications.Unencrypted","ruleName":"com.hcl.appscan.scanner.csharp.rules.OpenCommunicationCsharp","context":"\"http://{musicSettings.LavalinkHost}:2333\"","severity":2,"codeFixes":[{"description":"Use secure URI scheme","name":"com.ouncelabs.languagelite.common.rules.fix.SecureCommFix"}],"hashValues":{"0":1508174403,"1":1508174403,"2":-2032068290,"3":-2032068290,"4":-97441684,"5":-97441684}}

Check warning on line 83 in src/AzzyBot.Bot/Extensions/IServiceCollectionExtensions.cs

View workflow job for this annotation

GitHub Actions / AppScan CodeSweep #2

Open communication detected in Xamarin

Vulnerability: Communications.Unencrypted [Severity: Low]
Raw output
{"file":"IServiceCollectionExtensions.cs","filePath":"src/AzzyBot.Bot/Extensions/IServiceCollectionExtensions.cs","lineNumber":83,"columnNumber":0,"language":"Xamarin","vulnName":"Open communication detected in Xamarin","vulnType":"Communications.Unencrypted","ruleName":"com.hcl.appscan.scanner.xamarin.rules.OpenCommunicationXamarin","context":"\"http://{musicSettings.LavalinkHost}:2333\"","severity":2,"codeFixes":[{"description":"Use secure URI scheme","name":"com.ouncelabs.languagelite.common.rules.fix.SecureCommFix"}],"hashValues":{"0":1508174403,"1":1508174403,"2":-2032068290,"3":-2032068290,"4":1817155115,"5":1817155115}}
}
else if (string.IsNullOrWhiteSpace(settings.MusicStreaming.LavalinkHost) && settings.MusicStreaming.LavalinkPort is not 0)
else if (string.IsNullOrWhiteSpace(musicSettings.LavalinkHost) && musicSettings.LavalinkPort is not 0)
{
baseAddress = (isDocker) ? new($"http://AzzyBot-Ms:{settings.MusicStreaming.LavalinkPort}") : new($"http://localhost:{settings.MusicStreaming.LavalinkPort}");
baseAddress = (isDocker) ? new($"http://AzzyBot-Ms:{musicSettings.LavalinkPort}") : new($"http://localhost:{musicSettings.LavalinkPort}");

Check warning on line 87 in src/AzzyBot.Bot/Extensions/IServiceCollectionExtensions.cs

View workflow job for this annotation

GitHub Actions / AppScan CodeSweep #1

Open communications scheme detected

Vulnerability: Communications.Unencrypted [Severity: Low]
Raw output
{"file":"IServiceCollectionExtensions.cs","filePath":"src/AzzyBot.Bot/Extensions/IServiceCollectionExtensions.cs","lineNumber":87,"columnNumber":0,"language":"C#","vulnName":"Open communications scheme detected","vulnType":"Communications.Unencrypted","ruleName":"com.hcl.appscan.scanner.csharp.rules.OpenCommunicationCsharp","context":"\"http://AzzyBot-Ms:{musicSettings.LavalinkPort}\"","severity":2,"codeFixes":[{"description":"Use secure URI scheme","name":"com.ouncelabs.languagelite.common.rules.fix.SecureCommFix"}],"hashValues":{"0":504140531,"1":504140531,"2":-605201402,"3":-605201402,"4":1273561876,"5":1273561876}}

Check warning on line 87 in src/AzzyBot.Bot/Extensions/IServiceCollectionExtensions.cs

View workflow job for this annotation

GitHub Actions / AppScan CodeSweep #2

Open communication detected in Xamarin

Vulnerability: Communications.Unencrypted [Severity: Low]
Raw output
{"file":"IServiceCollectionExtensions.cs","filePath":"src/AzzyBot.Bot/Extensions/IServiceCollectionExtensions.cs","lineNumber":87,"columnNumber":0,"language":"Xamarin","vulnName":"Open communication detected in Xamarin","vulnType":"Communications.Unencrypted","ruleName":"com.hcl.appscan.scanner.xamarin.rules.OpenCommunicationXamarin","context":"\"http://AzzyBot-Ms:{musicSettings.LavalinkPort}\"","severity":2,"codeFixes":[{"description":"Use secure URI scheme","name":"com.ouncelabs.languagelite.common.rules.fix.SecureCommFix"}],"hashValues":{"0":504140531,"1":504140531,"2":-605201402,"3":-605201402,"4":1934270771,"5":1934270771}}

Check warning on line 87 in src/AzzyBot.Bot/Extensions/IServiceCollectionExtensions.cs

View workflow job for this annotation

GitHub Actions / AppScan CodeSweep #2

Open communication detected in Xamarin

Vulnerability: Communications.Unencrypted [Severity: Low]
Raw output
{"file":"IServiceCollectionExtensions.cs","filePath":"src/AzzyBot.Bot/Extensions/IServiceCollectionExtensions.cs","lineNumber":87,"columnNumber":0,"language":"Xamarin","vulnName":"Open communication detected in Xamarin","vulnType":"Communications.Unencrypted","ruleName":"com.hcl.appscan.scanner.xamarin.rules.OpenCommunicationXamarin","context":"\"http://localhost:{musicSettings.LavalinkPort}\"","severity":2,"codeFixes":[{"description":"Use secure URI scheme","name":"com.ouncelabs.languagelite.common.rules.fix.SecureCommFix"}],"hashValues":{"0":1099925168,"1":1099925168,"2":-1596616073,"3":-1596616073,"4":-2082101396,"5":-2082101396}}
}

if (!string.IsNullOrWhiteSpace(settings.MusicStreaming.LavalinkPassword))
config.Passphrase = settings.MusicStreaming.LavalinkPassword;
if (!string.IsNullOrWhiteSpace(musicSettings.LavalinkPassword))
config.Passphrase = musicSettings.LavalinkPassword;
}

config.BaseAddress = baseAddress;
Expand All @@ -100,17 +102,17 @@ public static void AzzyBotServices(this IServiceCollection services, bool isDev,
public static void AddAppSettings(this IServiceCollection services)
{
services.AddSingleton<IValidateOptions<AzzyBotSettings>, AzzyBotSettingsValidator>().AddOptionsWithValidateOnStart<AzzyBotSettings>();
services.AddSingleton<IValidateOptions<AppDatabaseSettings>, DatabaseSettingsValidator>().AddOptionsWithValidateOnStart<AppDatabaseSettings>();
services.AddSingleton<IValidateOptions<DiscordStatus>, DiscordStatusSettingsValidator>().AddOptionsWithValidateOnStart<DiscordStatus>();
services.AddSingleton<IValidateOptions<MusicStreaming>, MusicStreamingSettingsValidator>().AddOptionsWithValidateOnStart<MusicStreaming>();
services.AddSingleton<IValidateOptions<CoreUpdater>, CoreUpdaterValidator>().AddOptionsWithValidateOnStart<CoreUpdater>();
services.AddSingleton<IValidateOptions<DatabaseSettings>, DatabaseSettingsValidator>().AddOptionsWithValidateOnStart<DatabaseSettings>();
services.AddSingleton<IValidateOptions<DiscordStatusSettings>, DiscordStatusSettingsValidator>().AddOptionsWithValidateOnStart<DiscordStatusSettings>();
services.AddSingleton<IValidateOptions<MusicStreamingSettings>, MusicStreamingSettingsValidator>().AddOptionsWithValidateOnStart<MusicStreamingSettings>();
services.AddSingleton<IValidateOptions<CoreUpdaterSettings>, CoreUpdaterValidator>().AddOptionsWithValidateOnStart<CoreUpdaterSettings>();
services.AddSingleton<IValidateOptions<AppStats>, AppStatsValidator>().AddOptionsWithValidateOnStart<AppStats>();

services.AddOptions<AzzyBotSettings>().BindConfiguration(nameof(AzzyBotSettings));
services.AddOptions<AppDatabaseSettings>().BindConfiguration(nameof(AppDatabaseSettings));
services.AddOptions<DiscordStatus>().BindConfiguration(nameof(DiscordStatus));
services.AddOptions<MusicStreaming>().BindConfiguration(nameof(MusicStreaming));
services.AddOptions<CoreUpdater>().BindConfiguration(nameof(CoreUpdater));
services.AddOptions<DatabaseSettings>().BindConfiguration(nameof(DatabaseSettings));
services.AddOptions<DiscordStatusSettings>().BindConfiguration(nameof(DiscordStatusSettings));
services.AddOptions<MusicStreamingSettings>().BindConfiguration(nameof(MusicStreamingSettings));
services.AddOptions<CoreUpdaterSettings>().BindConfiguration(nameof(CoreUpdaterSettings));
services.AddOptions<AppStats>().BindConfiguration(nameof(AppStats));
}

Expand Down
5 changes: 3 additions & 2 deletions src/AzzyBot.Bot/Services/DiscordBotService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@
using DSharpPlus.Entities;
using DSharpPlus.Exceptions;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

namespace AzzyBot.Bot.Services;

public sealed class DiscordBotService(ILogger<DiscordBotService> logger, AzzyBotSettings settings, DbActions dbActions, DiscordClient client)
public sealed class DiscordBotService(ILogger<DiscordBotService> logger, IOptions<AzzyBotSettings> settings, DbActions dbActions, DiscordClient client)
{
private readonly ILogger<DiscordBotService> _logger = logger;
private readonly AzzyBotSettings _settings = settings;
private readonly AzzyBotSettings _settings = settings.Value;
private readonly DbActions _dbActions = dbActions;
private readonly DiscordClient _client = client;
private const string BugReportMessage = "Send a [bug report]([BugReportUri]) to help us fixing this issue!\nPlease include a screenshot of this exception embed and the attached StackTrace file.\nYour Contribution is very welcome.";
Expand Down
9 changes: 5 additions & 4 deletions src/AzzyBot.Bot/Services/DiscordBotServiceHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@
using DSharpPlus.Entities;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

namespace AzzyBot.Bot.Services;

public sealed class DiscordBotServiceHost(ILogger<DiscordBotServiceHost> logger, AzzyBotSettings settings, DiscordClient client) : IHostedService
public sealed class DiscordBotServiceHost(ILogger<DiscordBotServiceHost> logger, IOptions<DiscordStatusSettings> settings, DiscordClient client) : IHostedService
{
private readonly ILogger<DiscordBotServiceHost> _logger = logger;
private readonly AzzyBotSettings _settings = settings;
private readonly DiscordStatusSettings _settings = settings.Value;
private readonly DiscordClient _client = client;

public async Task StartAsync(CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();

DiscordActivity activity = DiscordBotService.SetBotStatusActivity(_settings.DiscordStatus?.Activity ?? 2, _settings.DiscordStatus?.Doing ?? "Music", _settings.DiscordStatus?.StreamUrl);
DiscordUserStatus status = DiscordBotService.SetBotStatusUserStatus(_settings.DiscordStatus?.Status ?? 1);
DiscordActivity activity = DiscordBotService.SetBotStatusActivity(_settings.Activity, _settings.Doing, _settings.StreamUrl);
DiscordUserStatus status = DiscordBotService.SetBotStatusUserStatus(_settings.Status);

await _client.ConnectAsync(activity, status);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
using DSharpPlus.Entities;
using DSharpPlus.EventArgs;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

namespace AzzyBot.Bot.Services.DiscordEvents;

public sealed class DiscordGuildsHandler(ILogger<DiscordGuildsHandler> logger, AzzyBotSettings settings, DiscordBotService botService, DbActions dbActions) : IEventHandler<GuildCreatedEventArgs>, IEventHandler<GuildDeletedEventArgs>, IEventHandler<GuildDownloadCompletedEventArgs>
public sealed class DiscordGuildsHandler(ILogger<DiscordGuildsHandler> logger, IOptions<AzzyBotSettings> settings, DiscordBotService botService, DbActions dbActions) : IEventHandler<GuildCreatedEventArgs>, IEventHandler<GuildDeletedEventArgs>, IEventHandler<GuildDownloadCompletedEventArgs>
{
private readonly ILogger<DiscordGuildsHandler> _logger = logger;
private readonly AzzyBotSettings _settings = settings;
private readonly AzzyBotSettings _settings = settings.Value;
private readonly DbActions _dbActions = dbActions;
private readonly DiscordBotService _botService = botService;

Expand Down
38 changes: 26 additions & 12 deletions src/AzzyBot.Bot/Services/Modules/CoreServiceHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,23 @@
using AzzyBot.Core.Utilities.Encryption;
using AzzyBot.Data;
using AzzyBot.Data.Entities;
using AzzyBot.Data.Settings;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

namespace AzzyBot.Bot.Services.Modules;

public sealed class CoreServiceHost(ILogger<CoreServiceHost> logger, AzzyBotSettings settings, AzzyDbContext dbContext) : IHostedService
public sealed class CoreServiceHost(ILogger<CoreServiceHost> logger, IOptions<AzzyBotSettings> azzySettings, IOptions<CoreUpdaterSettings> updaterSettings, IOptions<DatabaseSettings> dbSettings, IOptions<DiscordStatusSettings> discordSettings, IOptions<MusicStreamingSettings> musicStreamingSettings, AzzyDbContext dbContext) : IHostedService
{
private readonly ILogger<CoreServiceHost> _logger = logger;
private readonly AzzyBotSettings _settings = settings;
private readonly AzzyBotSettings _azzySettings = azzySettings.Value;
private readonly CoreUpdaterSettings _updaterSettings = updaterSettings.Value;
private readonly DatabaseSettings _dbSettings = dbSettings.Value;
private readonly DiscordStatusSettings _discordSettings = discordSettings.Value;
private readonly MusicStreamingSettings _musicStreamingSettings = musicStreamingSettings.Value;
private readonly AzzyDbContext _dbContext = dbContext;
private readonly Task _completed = Task.CompletedTask;

Expand All @@ -36,7 +42,7 @@ public async Task StartAsync(CancellationToken cancellationToken)

_logger.BotStarting(name, version, os, arch, dotnet);

if (_settings.Database is not null && !string.IsNullOrWhiteSpace(_settings.Database.NewEncryptionKey) && (_settings.Database.NewEncryptionKey != _settings.Database.EncryptionKey))
if (!string.IsNullOrWhiteSpace(_dbSettings.NewEncryptionKey) && (_dbSettings.NewEncryptionKey != _dbSettings.EncryptionKey))
await ReencryptDatabaseAsync();
}

Expand All @@ -49,14 +55,13 @@ public Task StopAsync(CancellationToken cancellationToken)

private async Task ReencryptDatabaseAsync()
{
ArgumentNullException.ThrowIfNull(_settings.Database);
ArgumentException.ThrowIfNullOrWhiteSpace(_settings.Database.EncryptionKey);
ArgumentException.ThrowIfNullOrWhiteSpace(_settings.Database.NewEncryptionKey);
ArgumentException.ThrowIfNullOrWhiteSpace(_settings.SettingsFile);
ArgumentException.ThrowIfNullOrWhiteSpace(_dbSettings.EncryptionKey);
ArgumentException.ThrowIfNullOrWhiteSpace(_dbSettings.NewEncryptionKey);
ArgumentException.ThrowIfNullOrWhiteSpace(_azzySettings.SettingsFile);

_logger.DatabaseReencryptionStart();

byte[] newEncryptionKey = Encoding.UTF8.GetBytes(_settings.Database.NewEncryptionKey);
byte[] newEncryptionKey = Encoding.UTF8.GetBytes(_dbSettings.NewEncryptionKey);

await using IDbContextTransaction transaction = await _dbContext.Database.BeginTransactionAsync();

Expand Down Expand Up @@ -90,11 +95,20 @@ private async Task ReencryptDatabaseAsync()
}

Crypto.EncryptionKey = newEncryptionKey;
_settings.Database.EncryptionKey = _settings.Database.NewEncryptionKey;
_settings.Database.NewEncryptionKey = string.Empty;
_dbSettings.EncryptionKey = _dbSettings.NewEncryptionKey;
_dbSettings.NewEncryptionKey = string.Empty;

string json = JsonSerializer.Serialize(_settings, JsonSerializationSourceGen.Default.AzzyBotSettingsRecord);
await FileOperations.WriteToFileAsync(_settings.SettingsFile, json);
AppSettingsRecord appSettings = new()
{
AzzyBotSettings = _azzySettings,
DatabaseSettings = _dbSettings,
DiscordStatusSettings = _discordSettings,
MusicStreamingSettings = _musicStreamingSettings,
CoreUpdaterSettings = _updaterSettings
};

string json = JsonSerializer.Serialize(appSettings, JsonSerializationSourceGen.Default.AppSettingsRecord);
await FileOperations.WriteToFileAsync(_azzySettings.SettingsFile, json);

_logger.DatabaseReencryptionComplete();
}
Expand Down
16 changes: 9 additions & 7 deletions src/AzzyBot.Bot/Services/UpdaterService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
using AzzyBot.Core.Utilities;
using DSharpPlus.Entities;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

namespace AzzyBot.Bot.Services;

public sealed class UpdaterService(ILogger<UpdaterService> logger, AzzyBotSettings settings, DiscordBotService botService, WebRequestService webService)
public sealed class UpdaterService(ILogger<UpdaterService> logger, IOptions<AzzyBotSettings> botSettings, IOptions<CoreUpdaterSettings> updaterSettings, DiscordBotService botService, WebRequestService webService)
{
private readonly ILogger<UpdaterService> _logger = logger;
private readonly AzzyBotSettings _settings = settings;
private readonly AzzyBotSettings _botSettings = botSettings.Value;
private readonly CoreUpdaterSettings _updaterSettings = updaterSettings.Value;
private readonly DiscordBotService _botService = botService;
private readonly WebRequestService _webService = webService;
private DateTimeOffset _lastAzzyUpdateNotificationTime = DateTimeOffset.MinValue;
Expand Down Expand Up @@ -102,26 +104,26 @@ private async Task SendUpdateMessageAsync(string updateVersion, DateTimeOffset r
EmbedBuilder.BuildAzzyUpdatesAvailableEmbed(updateVersion, releaseDate, _latestUrl)
};

if (_settings.Updater.DisplayChangelog)
if (_updaterSettings.DisplayChangelog)
embeds.Add(EmbedBuilder.BuildAzzyUpdatesChangelogEmbed(changelog, _latestUrl));

if (_settings.Updater.DisplayInstructions)
if (_updaterSettings.DisplayInstructions)
embeds.Add(EmbedBuilder.BuildAzzyUpdatesInstructionsEmbed());

DiscordGuild? discordGuild = _botService.GetDiscordGuild();
if (discordGuild is null)
{
_logger.DiscordItemNotFound(nameof(DiscordGuild), _settings.ServerId);
_logger.DiscordItemNotFound(nameof(DiscordGuild), _botSettings.ServerId);
return;
}

ulong channelId = _settings.NotificationChannelId;
ulong channelId = _botSettings.NotificationChannelId;
if (channelId is 0)
{
DiscordChannel? discordChannel = await discordGuild.GetSystemChannelAsync();
if (discordChannel is null)
{
_logger.DiscordItemNotFound(nameof(DiscordChannel), _settings.ServerId);
_logger.DiscordItemNotFound(nameof(DiscordChannel), _botSettings.ServerId);
return;
}

Expand Down
12 changes: 12 additions & 0 deletions src/AzzyBot.Bot/Settings/AppSettingsRecord.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using AzzyBot.Data.Settings;

namespace AzzyBot.Bot.Settings;

public sealed record AppSettingsRecord
{
public required AzzyBotSettings AzzyBotSettings { get; init; }
public required DatabaseSettings DatabaseSettings { get; init; }
public required DiscordStatusSettings DiscordStatusSettings { get; init; }
public required MusicStreamingSettings MusicStreamingSettings { get; init; }
public required CoreUpdaterSettings CoreUpdaterSettings { get; init; }
}
8 changes: 4 additions & 4 deletions src/AzzyBot.Bot/Settings/AzzyBotSettings-Docker.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
"ErrorChannelId": 0,
"NotificationChannelId": 0
},
"Database": {
"DatabaseSettings": {
"EncryptionKey": null,
"NewEncryptionKey": null
},
"DiscordStatus": {
"DiscordStatusSettings": {
"Activity": 2,
"Doing": "Music",
"Status": 1,
"StreamUrl": null
},
"MusicStreaming": {
"MusicStreamingSettings": {
"LavalinkPassword": "AzzyB0TMus1cStr3am!ng"
},
"CoreUpdater": {
"CoreUpdaterSettings": {
"DisplayChangelog": true,
"DisplayInstructions": true
}
Expand Down
Loading

0 comments on commit af3c70e

Please sign in to comment.