From ae60bbdb5b3214f857c9600c3ece97f0b2ef1b60 Mon Sep 17 00:00:00 2001 From: Nikita Petko Date: Wed, 3 Jul 2024 14:06:59 +0100 Subject: [PATCH] Update to systems Projects: ~ Bump to all new package versions in respect to mfdlabs/grid-bot-libraries#29 ~ Bump Discord.Net to 3.15.2 OnLogMessage.cs: ~ Add system to consider connection based messages to be debug, instead of filling log files with junk AvatarUtility.cs: ~ Throw thumbnail exception if the response from the thumbnail download request returns null. --- .../lib/commands/Shared.Commands.csproj | 12 ++++++------ .../lib/events/Events/OnLogMessage.cs | 19 +++++++++++++++++-- .../grid-bot/lib/events/Shared.Events.csproj | 6 +++--- .../lib/settings/Shared.Settings.csproj | 14 +++++++------- .../utility/Implementation/AvatarUtility.cs | 2 ++ .../lib/utility/Shared.Utility.csproj | 12 ++++++------ services/grid-bot/src/Grid.Bot.csproj | 8 ++++---- .../recovery/src/Grid.Bot.Recovery.csproj | 10 +++++----- 8 files changed, 50 insertions(+), 33 deletions(-) diff --git a/services/grid-bot/lib/commands/Shared.Commands.csproj b/services/grid-bot/lib/commands/Shared.Commands.csproj index 0e3aeefe..53a38279 100644 --- a/services/grid-bot/lib/commands/Shared.Commands.csproj +++ b/services/grid-bot/lib/commands/Shared.Commands.csproj @@ -15,11 +15,11 @@ - + - + - + @@ -32,9 +32,9 @@ - - - + + + diff --git a/services/grid-bot/lib/events/Events/OnLogMessage.cs b/services/grid-bot/lib/events/Events/OnLogMessage.cs index 8a4c813f..bb9b9444 100644 --- a/services/grid-bot/lib/events/Events/OnLogMessage.cs +++ b/services/grid-bot/lib/events/Events/OnLogMessage.cs @@ -1,8 +1,10 @@ namespace Grid.Bot.Events; using System; +using System.Linq; using System.Net.WebSockets; using System.Threading.Tasks; +using System.Collections.Generic; using Discord; using Discord.Net; @@ -20,7 +22,7 @@ public class OnLogMessage { private readonly DiscordSettings _settings; - + #if DEBUG || DEBUG_LOGGING_IN_PROD private readonly IDiscordWebhookAlertManager _discordWebhookAlertManager; private readonly IBacktraceUtility _backtraceUtility; @@ -34,6 +36,16 @@ public class OnLogMessage "log_severity" ); + // These are specific strings that fill the log files up drastically. + private static readonly HashSet _messagesToBeConsideredDebug = new() + { + "Disconnecting", + "Disconnected", + "Connecting", + "Connected", + "Resumed previous session" + }; + #if DEBUG || DEBUG_LOGGING_IN_PROD /// /// Construct a new instance of . @@ -134,7 +146,10 @@ public Task Invoke(LogMessage message) _logger.Debug("{0}: {1}", message.Source, message.Message); break; case { Severity: LogSeverity.Info }: - _logger.Information("{0}: {1}", message.Source, message.Message); + if (_messagesToBeConsideredDebug.Any(m => m.Equals(message.Message, StringComparison.Ordinal))) + _logger.Debug("{0}: {1}", message.Source, message.Message); + else + _logger.Information("{0}: {1}", message.Source, message.Message); break; case { Severity: LogSeverity.Verbose }: _logger.Debug("{0}: {1}", message.Source, message.Message); diff --git a/services/grid-bot/lib/events/Shared.Events.csproj b/services/grid-bot/lib/events/Shared.Events.csproj index 541da7a6..a800902d 100644 --- a/services/grid-bot/lib/events/Shared.Events.csproj +++ b/services/grid-bot/lib/events/Shared.Events.csproj @@ -10,9 +10,9 @@ - - - + + + diff --git a/services/grid-bot/lib/settings/Shared.Settings.csproj b/services/grid-bot/lib/settings/Shared.Settings.csproj index 7b50a099..fbd01d33 100644 --- a/services/grid-bot/lib/settings/Shared.Settings.csproj +++ b/services/grid-bot/lib/settings/Shared.Settings.csproj @@ -11,19 +11,19 @@ - - + + - + - - + + - - + + diff --git a/services/grid-bot/lib/utility/Implementation/AvatarUtility.cs b/services/grid-bot/lib/utility/Implementation/AvatarUtility.cs index 2bc54ce5..93cb9fbc 100644 --- a/services/grid-bot/lib/utility/Implementation/AvatarUtility.cs +++ b/services/grid-bot/lib/utility/Implementation/AvatarUtility.cs @@ -191,6 +191,8 @@ private static string DownloadFile(string url) using var client = new HttpClient(); using var stream = client.GetStreamAsync(url).SyncOrDefault(); + if (stream == null) throw new ThumbnailResponseException(ThumbnailResponseState.Error, "The thumbnail response stream was null"); + stream.CopyTo(file); file.Close(); diff --git a/services/grid-bot/lib/utility/Shared.Utility.csproj b/services/grid-bot/lib/utility/Shared.Utility.csproj index efb96713..d2ed19d6 100644 --- a/services/grid-bot/lib/utility/Shared.Utility.csproj +++ b/services/grid-bot/lib/utility/Shared.Utility.csproj @@ -13,19 +13,19 @@ - + - + - + - - + + @@ -50,7 +50,7 @@ - + diff --git a/services/grid-bot/src/Grid.Bot.csproj b/services/grid-bot/src/Grid.Bot.csproj index 3c49776e..1ca04b36 100644 --- a/services/grid-bot/src/Grid.Bot.csproj +++ b/services/grid-bot/src/Grid.Bot.csproj @@ -25,7 +25,7 @@ - + @@ -37,9 +37,9 @@ - - - + + + diff --git a/services/recovery/src/Grid.Bot.Recovery.csproj b/services/recovery/src/Grid.Bot.Recovery.csproj index 2067c5e4..e466bb9b 100644 --- a/services/recovery/src/Grid.Bot.Recovery.csproj +++ b/services/recovery/src/Grid.Bot.Recovery.csproj @@ -15,9 +15,9 @@ - + - + @@ -29,9 +29,9 @@ - - - + + +