From 91da4e7ece6e1a6d3404556c5e67acf8c4e7964f Mon Sep 17 00:00:00 2001 From: 13xforever Date: Wed, 9 Nov 2022 09:41:09 +0500 Subject: [PATCH] fix new compiler warnings --- Clients/CirrusCiClient/CirrusCi.cs | 2 +- Clients/PsnClient/PsnClient.cs | 2 +- CompatBot/Config.cs | 28 +++++++++---------- .../EventHandlers/DiscordInviteFilter.cs | 4 +-- .../EventHandlers/EmpathySimulationHandler.cs | 6 ++-- .../EventHandlers/UsernameSpoofMonitor.cs | 2 +- .../Extensions/AzureDevOpsClientExtensions.cs | 6 ++-- .../Utils/Extensions/PsnMetaExtensions.cs | 2 +- CompatBot/Utils/Extensions/StringUtils.cs | 3 +- 9 files changed, 29 insertions(+), 26 deletions(-) diff --git a/Clients/CirrusCiClient/CirrusCi.cs b/Clients/CirrusCiClient/CirrusCi.cs index 2d2fec27..ee209978 100644 --- a/Clients/CirrusCiClient/CirrusCi.cs +++ b/Clients/CirrusCiClient/CirrusCi.cs @@ -94,7 +94,7 @@ public static class CirrusCi public static async Task GetPipelineDurationAsync(CancellationToken cancellationToken) { const string cacheKey = "project-build-stats"; - if (BuildInfoCache.TryGetValue(cacheKey, out ProjectBuildStats result)) + if (BuildInfoCache.TryGetValue(cacheKey, out ProjectBuildStats? result) && result is not null) return result; try diff --git a/Clients/PsnClient/PsnClient.cs b/Clients/PsnClient/PsnClient.cs index bb00a8ad..0bad2f16 100644 --- a/Clients/PsnClient/PsnClient.cs +++ b/Clients/PsnClient/PsnClient.cs @@ -239,7 +239,7 @@ public class Client if (string.IsNullOrEmpty(productId)) return default; - if (ResponseCache.TryGetValue(productId, out TitlePatch patchInfo)) + if (ResponseCache.TryGetValue(productId, out TitlePatch? patchInfo)) return (patchInfo, default); using var message = new HttpRequestMessage(HttpMethod.Get, $"https://a0.ww.np.dl.playstation.net/tpl/np/{productId}/{productId}-ver.xml"); diff --git a/CompatBot/Config.cs b/CompatBot/Config.cs index 57ebecf2..78cf716c 100644 --- a/CompatBot/Config.cs +++ b/CompatBot/Config.cs @@ -37,15 +37,15 @@ internal static class Config internal static readonly ILogger Log; internal static readonly ILoggerFactory LoggerFactory; - internal static readonly ConcurrentDictionary InMemorySettings = new(); + internal static readonly ConcurrentDictionary InMemorySettings = new(); internal static readonly RecyclableMemoryStreamManager MemoryStreamManager = new(); public static readonly CancellationTokenSource Cts = new(); public static readonly Stopwatch Uptime = Stopwatch.StartNew(); // these settings could be configured either through `$ dotnet user-secrets`, or through environment variables (e.g. launchSettings.json, etc) - public static string CommandPrefix => config.GetValue(nameof(CommandPrefix), "!"); - public static string AutoRemoveCommandPrefix => config.GetValue(nameof(AutoRemoveCommandPrefix), "."); + public static string CommandPrefix => config.GetValue(nameof(CommandPrefix), "!")!; + public static string AutoRemoveCommandPrefix => config.GetValue(nameof(AutoRemoveCommandPrefix), ".")!; public static ulong BotGuildId => config.GetValue(nameof(BotGuildId), 272035812277878785ul); // discord server where the bot is supposed to be public static ulong BotGeneralChannelId => config.GetValue(nameof(BotGeneralChannelId), 272035812277878785ul);// #rpcs3; main or general channel where noobs come first thing public static ulong BotChannelId => config.GetValue(nameof(BotChannelId), 291679908067803136ul); // #build-updates; this is used for new build announcements @@ -77,19 +77,19 @@ internal static class Config public static int ChannelMessageHistorySize => config.GetValue(nameof(ChannelMessageHistorySize), 100); public static int FunMultiplier => config.GetValue(nameof(FunMultiplier), 1); public static int MaxPositionsForHwSurveyResults => config.GetValue(nameof(MaxPositionsForHwSurveyResults), 10); - public static string Token => config.GetValue(nameof(Token), ""); - public static string AzureDevOpsToken => config.GetValue(nameof(AzureDevOpsToken), ""); - public static string AzureComputerVisionKey => config.GetValue(nameof(AzureComputerVisionKey), ""); - public static string AzureComputerVisionEndpoint => config.GetValue(nameof(AzureComputerVisionEndpoint), "https://westeurope.api.cognitive.microsoft.com/"); + public static string Token => config.GetValue(nameof(Token), "")!; + public static string AzureDevOpsToken => config.GetValue(nameof(AzureDevOpsToken), "")!; + public static string AzureComputerVisionKey => config.GetValue(nameof(AzureComputerVisionKey), "")!; + public static string AzureComputerVisionEndpoint => config.GetValue(nameof(AzureComputerVisionEndpoint), "https://westeurope.api.cognitive.microsoft.com/")!; public static Guid AzureDevOpsProjectId => config.GetValue(nameof(AzureDevOpsProjectId), new Guid("3598951b-4d39-4fad-ad3b-ff2386a649de")); - public static string AzureAppInsightsConnectionString => config.GetValue(nameof(AzureAppInsightsConnectionString), ""); - public static string GithubToken => config.GetValue(nameof(GithubToken), ""); - public static string PreferredFontFamily => config.GetValue(nameof(PreferredFontFamily), ""); - public static string LogPath => config.GetValue(nameof(LogPath), "./logs/"); // paths are relative to the working directory - public static string IrdCachePath => config.GetValue(nameof(IrdCachePath), "./ird/"); + public static string AzureAppInsightsConnectionString => config.GetValue(nameof(AzureAppInsightsConnectionString), "")!; + public static string GithubToken => config.GetValue(nameof(GithubToken), "")!; + public static string PreferredFontFamily => config.GetValue(nameof(PreferredFontFamily), "")!; + public static string LogPath => config.GetValue(nameof(LogPath), "./logs/")!; // paths are relative to the working directory + public static string IrdCachePath => config.GetValue(nameof(IrdCachePath), "./ird/")!; public static double GameTitleMatchThreshold => config.GetValue(nameof(GameTitleMatchThreshold), 0.57); - public static byte[] CryptoSalt => Convert.FromBase64String(config.GetValue(nameof(CryptoSalt), "")); - public static string RenameNameSuffix => config.GetValue(nameof(RenameNameSuffix), " (Rule 7)"); + public static byte[] CryptoSalt => Convert.FromBase64String(config.GetValue(nameof(CryptoSalt), "")!); + public static string RenameNameSuffix => config.GetValue(nameof(RenameNameSuffix), " (Rule 7)")!; internal static class AllowedMentions { diff --git a/CompatBot/EventHandlers/DiscordInviteFilter.cs b/CompatBot/EventHandlers/DiscordInviteFilter.cs index 7360408b..2078a0fe 100644 --- a/CompatBot/EventHandlers/DiscordInviteFilter.cs +++ b/CompatBot/EventHandlers/DiscordInviteFilter.cs @@ -129,7 +129,7 @@ internal static class DiscordInviteFilter { if (!await InviteWhitelistProvider.IsWhitelistedAsync(invite).ConfigureAwait(false)) { - if (!InviteCodeCache.TryGetValue(message.Author.Id, out HashSet recentInvites)) + if (!InviteCodeCache.TryGetValue(message.Author.Id, out HashSet? recentInvites) || recentInvites is null) recentInvites = new(); var repeatedInvitePost = !recentInvites.Add(invite.Code); var circumventionAttempt = repeatedInvitePost && attemptedWorkaround; @@ -195,7 +195,7 @@ internal static class DiscordInviteFilter var inviteCodes = new HashSet(InviteLink.Matches(message).Select(m => m.Groups["invite_id"].Value).Where(s => !string.IsNullOrEmpty(s))); var discordMeLinks = InviteLink.Matches(message).Select(m => m.Groups["me_id"].Value).Distinct().Where(s => !string.IsNullOrEmpty(s)).ToList(); var attemptedWorkaround = false; - if (author != null && InviteCodeCache.TryGetValue(author.Id, out HashSet recentInvites)) + if (author != null && InviteCodeCache.TryGetValue(author.Id, out HashSet? recentInvites) && recentInvites is not null) { foreach (var c in recentInvites) if (message.Contains(c)) diff --git a/CompatBot/EventHandlers/EmpathySimulationHandler.cs b/CompatBot/EventHandlers/EmpathySimulationHandler.cs index 2f0cda3b..6f1cbcf2 100644 --- a/CompatBot/EventHandlers/EmpathySimulationHandler.cs +++ b/CompatBot/EventHandlers/EmpathySimulationHandler.cs @@ -44,7 +44,9 @@ internal static class EmpathySimulationHandler return; //todo: throttle multiple strings at the same time - if (Throttling.TryGetValue(args.Channel.Id, out List mark) && content.Equals(mark.FirstOrDefault()?.Content, StringComparison.OrdinalIgnoreCase)) + if (Throttling.TryGetValue(args.Channel.Id, out List? mark) + && mark is not null + && content.Equals(mark.FirstOrDefault()?.Content, StringComparison.OrdinalIgnoreCase)) { mark.Add(args.Message); Config.Log.Debug($"Bailed out of repeating '{content}' due to throttling"); @@ -81,7 +83,7 @@ internal static class EmpathySimulationHandler if (message.Author.IsCurrent) return; - if (!Throttling.TryGetValue(channel.Id, out List msgList)) + if (!Throttling.TryGetValue(channel.Id, out List? msgList) || msgList is null) return; if (msgList.Any(m => m.Id == message.Id)) diff --git a/CompatBot/EventHandlers/UsernameSpoofMonitor.cs b/CompatBot/EventHandlers/UsernameSpoofMonitor.cs index 9a4fa10f..4df81003 100644 --- a/CompatBot/EventHandlers/UsernameSpoofMonitor.cs +++ b/CompatBot/EventHandlers/UsernameSpoofMonitor.cs @@ -106,7 +106,7 @@ internal static class UsernameSpoofMonitor try { var displayName = GetCanonical(potentialVictims[0].DisplayName); - if (SpoofingReportThrottlingCache.TryGetValue(displayName, out string s) && !string.IsNullOrEmpty(s)) + if (SpoofingReportThrottlingCache.TryGetValue(displayName, out string? s) && !string.IsNullOrEmpty(s)) { SpoofingReportThrottlingCache.Set(displayName, s, SnoozeDuration); return true; diff --git a/CompatBot/Utils/Extensions/AzureDevOpsClientExtensions.cs b/CompatBot/Utils/Extensions/AzureDevOpsClientExtensions.cs index 48199ded..34dac23f 100644 --- a/CompatBot/Utils/Extensions/AzureDevOpsClientExtensions.cs +++ b/CompatBot/Utils/Extensions/AzureDevOpsClientExtensions.cs @@ -58,7 +58,7 @@ internal static class AzureDevOpsClientExtensions public static async Task GetPipelineDurationAsync(this BuildHttpClient? azureDevOpsClient, CancellationToken cancellationToken) { const string cacheKey = "pipeline-duration"; - if (BuildInfoCache.TryGetValue(cacheKey, out PipelineStats result)) + if (BuildInfoCache.TryGetValue(cacheKey, out PipelineStats? result) && result is not null) return result; if (azureDevOpsClient is null) @@ -131,7 +131,7 @@ internal static class AzureDevOpsClientExtensions return null; commit = commit.ToLower(); - if (BuildInfoCache.TryGetValue(commit, out BuildInfo result)) + if (BuildInfoCache.TryGetValue(commit, out BuildInfo? result) && result is not null) return result; var builds = await azureDevOpsClient.GetBuildsAsync( @@ -165,7 +165,7 @@ internal static class AzureDevOpsClientExtensions return null; commit = commit.ToLower(); - if (BuildInfoCache.TryGetValue(commit, out BuildInfo result)) + if (BuildInfoCache.TryGetValue(commit, out BuildInfo? result) && result is not null) return result; var builds = await azureDevOpsClient.GetBuildsAsync( diff --git a/CompatBot/Utils/Extensions/PsnMetaExtensions.cs b/CompatBot/Utils/Extensions/PsnMetaExtensions.cs index 2cb458a6..ca98d45c 100644 --- a/CompatBot/Utils/Extensions/PsnMetaExtensions.cs +++ b/CompatBot/Utils/Extensions/PsnMetaExtensions.cs @@ -17,7 +17,7 @@ public static class PsnMetaExtensions internal static List<(string resolution, string aspectRatio)> GetSupportedResolutions(string resolutionList) { - if (ParsedData.TryGetValue(resolutionList, out List<(string, string)> result)) + if (ParsedData.TryGetValue(resolutionList, out List<(string, string)>? result) && result is not null) return result; var resList = resolutionList diff --git a/CompatBot/Utils/Extensions/StringUtils.cs b/CompatBot/Utils/Extensions/StringUtils.cs index d5c8ef8c..0a4f0cb2 100644 --- a/CompatBot/Utils/Extensions/StringUtils.cs +++ b/CompatBot/Utils/Extensions/StringUtils.cs @@ -426,7 +426,8 @@ public static class StringUtils strA = strA?.ToLowerInvariant() ?? ""; strB = strB?.ToLowerInvariant() ?? ""; var cacheKey = GetFuzzyCacheKey(strA, strB); - if (!FuzzyPairCache.TryGetValue(cacheKey, out FuzzyCacheValue match) + if (!FuzzyPairCache.TryGetValue(cacheKey, out FuzzyCacheValue? match) + || match is null || strA != match.StrA || strB != match.StrB) match = new FuzzyCacheValue