From 079dcbcc5cec5efcf9ab21c879d9b545c26998d4 Mon Sep 17 00:00:00 2001 From: 13xforever Date: Mon, 20 Jun 2022 17:14:32 +0500 Subject: [PATCH] clean up some warnings --- Clients/CirrusCiClient/.graphqlrc.json | 4 +-- Clients/CirrusCiClient/CirrusCi.cs | 1 + Clients/CirrusCiClient/CirrusCiClient.csproj | 2 +- Clients/CirrusCiClient/POCOs/BuildInfo.cs | 1 + Clients/CompatApiClient/Client.cs | 3 ++- Clients/IrdLibraryClient/IrdClient.cs | 3 ++- Clients/MediafireClient/Client.cs | 3 ++- Clients/OneDriveClient/Client.cs | 3 ++- Clients/PsnClient/PsnClient.cs | 7 ++--- Clients/YandexDiskClient/Client.cs | 3 ++- .../Attributes/LimitedToHelpChannel.cs | 2 +- .../Attributes/LimitedToOfftopicChannel.cs | 5 +++- .../Attributes/LimitedToSpamChannel.cs | 3 +++ CompatBot/Commands/BaseCommandModuleCustom.cs | 20 +++++++------- CompatBot/Commands/BotMath.cs | 9 ++++--- CompatBot/Commands/CommandsManagement.cs | 8 +++--- CompatBot/Commands/ContentFilters.cs | 2 +- CompatBot/Commands/EventsBaseCommand.cs | 2 +- CompatBot/Commands/Fortune.cs | 2 +- CompatBot/Commands/Pr.cs | 26 ++++++++++--------- CompatBot/Commands/Warnings.cs | 2 +- .../Database/NamingConventionConverter.cs | 12 ++++++--- .../EventHandlers/UnknownCommandHandler.cs | 2 +- .../Extensions/CommandContextExtensions.cs | 2 +- 24 files changed, 75 insertions(+), 52 deletions(-) diff --git a/Clients/CirrusCiClient/.graphqlrc.json b/Clients/CirrusCiClient/.graphqlrc.json index a9634017..37a50013 100644 --- a/Clients/CirrusCiClient/.graphqlrc.json +++ b/Clients/CirrusCiClient/.graphqlrc.json @@ -4,10 +4,10 @@ "extensions": { "strawberryShake": { "name": "Client", - "namespace": "CirrusCiClient", + "namespace": "CirrusCiClient.Generated", "url": "https://api.cirrus-ci.com/graphql", "dependencyInjection": true, - "emitGeneratedCode": false + "emitGeneratedCode": true } } } \ No newline at end of file diff --git a/Clients/CirrusCiClient/CirrusCi.cs b/Clients/CirrusCiClient/CirrusCi.cs index 81c54ef8..01aa7bea 100644 --- a/Clients/CirrusCiClient/CirrusCi.cs +++ b/Clients/CirrusCiClient/CirrusCi.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; +using CirrusCiClient.Generated; using CirrusCiClient.POCOs; using CompatApiClient; using CompatApiClient.Utils; diff --git a/Clients/CirrusCiClient/CirrusCiClient.csproj b/Clients/CirrusCiClient/CirrusCiClient.csproj index cba2c1dd..791e3675 100644 --- a/Clients/CirrusCiClient/CirrusCiClient.csproj +++ b/Clients/CirrusCiClient/CirrusCiClient.csproj @@ -2,7 +2,7 @@ net6.0 enable - true + false diff --git a/Clients/CirrusCiClient/POCOs/BuildInfo.cs b/Clients/CirrusCiClient/POCOs/BuildInfo.cs index 4ea1eaab..7871bbb1 100644 --- a/Clients/CirrusCiClient/POCOs/BuildInfo.cs +++ b/Clients/CirrusCiClient/POCOs/BuildInfo.cs @@ -1,4 +1,5 @@ using System; +using CirrusCiClient.Generated; namespace CirrusCiClient.POCOs { diff --git a/Clients/CompatApiClient/Client.cs b/Clients/CompatApiClient/Client.cs index c765de56..a8799e14 100644 --- a/Clients/CompatApiClient/Client.cs +++ b/Clients/CompatApiClient/Client.cs @@ -2,6 +2,7 @@ using System.Net.Http; using System.Net.Http.Json; using System.Text.Json; +using System.Text.Json.Serialization; using System.Threading; using System.Threading.Tasks; using CompatApiClient.Compression; @@ -24,7 +25,7 @@ namespace CompatApiClient jsonOptions = new JsonSerializerOptions { PropertyNamingPolicy = SpecialJsonNamingPolicy.SnakeCase, - IgnoreNullValues = true, + DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, IncludeFields = true, Converters = { new CompatApiCommitHashConverter(), }, }; diff --git a/Clients/IrdLibraryClient/IrdClient.cs b/Clients/IrdLibraryClient/IrdClient.cs index 0f0bdd98..2df686d3 100644 --- a/Clients/IrdLibraryClient/IrdClient.cs +++ b/Clients/IrdLibraryClient/IrdClient.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using System.Net.Http; using System.Text.Json; +using System.Text.Json.Serialization; using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; @@ -31,7 +32,7 @@ namespace IrdLibraryClient jsonOptions = new JsonSerializerOptions { PropertyNamingPolicy = SpecialJsonNamingPolicy.SnakeCase, - IgnoreNullValues = true, + DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, IncludeFields = true, }; } diff --git a/Clients/MediafireClient/Client.cs b/Clients/MediafireClient/Client.cs index 45d6abd0..62cff24e 100644 --- a/Clients/MediafireClient/Client.cs +++ b/Clients/MediafireClient/Client.cs @@ -10,6 +10,7 @@ using CompatApiClient; using CompatApiClient.Compression; using CompatApiClient.Utils; using System.Text.Json; +using System.Text.Json.Serialization; using System.Text.RegularExpressions; using CompatApiClient.Formatters; using MediafireClient.POCOs; @@ -32,7 +33,7 @@ namespace MediafireClient jsonOptions = new() { PropertyNamingPolicy = SpecialJsonNamingPolicy.SnakeCase, - IgnoreNullValues = true, + DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, IncludeFields = true, }; } diff --git a/Clients/OneDriveClient/Client.cs b/Clients/OneDriveClient/Client.cs index d2fb0cce..8ae4bb90 100644 --- a/Clients/OneDriveClient/Client.cs +++ b/Clients/OneDriveClient/Client.cs @@ -7,6 +7,7 @@ using CompatApiClient; using CompatApiClient.Compression; using CompatApiClient.Utils; using System.Text.Json; +using System.Text.Json.Serialization; using OneDriveClient.POCOs; namespace OneDriveClient @@ -24,7 +25,7 @@ namespace OneDriveClient jsonOptions = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, - IgnoreNullValues = true, + DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, IncludeFields = true, }; } diff --git a/Clients/PsnClient/PsnClient.cs b/Clients/PsnClient/PsnClient.cs index 1b4a62bc..21dcae72 100644 --- a/Clients/PsnClient/PsnClient.cs +++ b/Clients/PsnClient/PsnClient.cs @@ -6,6 +6,7 @@ using System.Net.Http; using System.Net.Http.Formatting; using System.Net.Http.Json; using System.Text.Json; +using System.Text.Json.Serialization; using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; @@ -49,13 +50,13 @@ namespace PsnClient dashedJson = new JsonSerializerOptions { PropertyNamingPolicy = SpecialJsonNamingPolicy.Dashed, - IgnoreNullValues = true, + DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, IncludeFields = true, }; snakeJson = new JsonSerializerOptions { PropertyNamingPolicy = SpecialJsonNamingPolicy.SnakeCase, - IgnoreNullValues = true, + DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, IncludeFields = true, }; xmlFormatters = new MediaTypeFormatterCollection(new[] {new XmlMediaTypeFormatter {UseXmlSerializer = true}}); @@ -301,7 +302,7 @@ namespace PsnClient try { var (language, country) = locale.AsLocaleData(); - var searchId = Uri.EscapeUriString(search); + var searchId = Uri.EscapeDataString(search); // was EscapeUriString for some reason I don't remember exactly var queryId = Uri.EscapeDataString(searchId); var uri = new Uri($"https://store.playstation.com/valkyrie-api/{language}/{country}/999/faceted-search/{searchId}?query={queryId}&game_content_type=games&size=30&bucket=games&platform=ps3&start=0"); using var message = new HttpRequestMessage(HttpMethod.Get, uri); diff --git a/Clients/YandexDiskClient/Client.cs b/Clients/YandexDiskClient/Client.cs index 087d0f12..4285b6c9 100644 --- a/Clients/YandexDiskClient/Client.cs +++ b/Clients/YandexDiskClient/Client.cs @@ -7,6 +7,7 @@ using CompatApiClient; using CompatApiClient.Compression; using CompatApiClient.Utils; using System.Text.Json; +using System.Text.Json.Serialization; using CompatApiClient.Formatters; using YandexDiskClient.POCOs; @@ -23,7 +24,7 @@ namespace YandexDiskClient jsonOptions = new JsonSerializerOptions { PropertyNamingPolicy = SpecialJsonNamingPolicy.SnakeCase, - IgnoreNullValues = true, + DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, IncludeFields = true, }; } diff --git a/CompatBot/Commands/Attributes/LimitedToHelpChannel.cs b/CompatBot/Commands/Attributes/LimitedToHelpChannel.cs index ccdc2fab..01f96e3e 100644 --- a/CompatBot/Commands/Attributes/LimitedToHelpChannel.cs +++ b/CompatBot/Commands/Attributes/LimitedToHelpChannel.cs @@ -16,7 +16,7 @@ namespace CompatBot.Commands.Attributes if (ctx.Channel.Name.Equals("help", StringComparison.InvariantCultureIgnoreCase)) return true; - await ctx.Channel.SendMessageAsync($"`{ctx.Prefix}{ctx.Command.QualifiedName}` is limited to help channel and DMs").ConfigureAwait(false); + await ctx.Channel.SendMessageAsync($"`{ctx.Prefix}{ctx.Command?.QualifiedName ?? ctx.RawArgumentString}` is limited to help channel and DMs").ConfigureAwait(false); return false; } } diff --git a/CompatBot/Commands/Attributes/LimitedToOfftopicChannel.cs b/CompatBot/Commands/Attributes/LimitedToOfftopicChannel.cs index cd0f1e2c..3f78dcf2 100644 --- a/CompatBot/Commands/Attributes/LimitedToOfftopicChannel.cs +++ b/CompatBot/Commands/Attributes/LimitedToOfftopicChannel.cs @@ -14,9 +14,12 @@ namespace CompatBot.Commands.Attributes { public override async Task ExecuteCheckAsync(CommandContext ctx, bool help) { - if (help || LimitedToSpamChannel.IsSpamChannel(ctx.Channel) || IsOfftopicChannel(ctx.Channel)) + if (help || LimitedToSpamChannel.IsSpamChannel(ctx.Channel) || IsOfftopicChannel(ctx.Channel)) return true; + if (ctx.Command is null) + return false; + try { var msgList = await ctx.Channel.GetMessagesCachedAsync(10).ConfigureAwait(false); diff --git a/CompatBot/Commands/Attributes/LimitedToSpamChannel.cs b/CompatBot/Commands/Attributes/LimitedToSpamChannel.cs index 2c2d9281..968576c4 100644 --- a/CompatBot/Commands/Attributes/LimitedToSpamChannel.cs +++ b/CompatBot/Commands/Attributes/LimitedToSpamChannel.cs @@ -17,6 +17,9 @@ namespace CompatBot.Commands.Attributes if (help || IsSpamChannel(ctx.Channel)) return true; + if (ctx.Command is null) + return false; + try { var msgList = await ctx.Channel.GetMessagesCachedAsync(10).ConfigureAwait(false); diff --git a/CompatBot/Commands/BaseCommandModuleCustom.cs b/CompatBot/Commands/BaseCommandModuleCustom.cs index 73f52d6e..363f8950 100644 --- a/CompatBot/Commands/BaseCommandModuleCustom.cs +++ b/CompatBot/Commands/BaseCommandModuleCustom.cs @@ -33,7 +33,7 @@ namespace CompatBot.Commands Config.Log.Warn(e, "Failed to delete command message with the autodelete command prefix"); } - if (ctx.Channel.Name == "media" && ctx.Command.QualifiedName != "warn" && ctx.Command.QualifiedName != "report") + if (ctx.Channel.Name == "media" && ctx.Command is { QualifiedName: not ("warn" or "report") }) { Config.Log.Info($"Ignoring command from {ctx.User.Username} (<@{ctx.User.Id}>) in #media: {ctx.Message.Content}"); if (ctx.Member is DiscordMember member) @@ -41,12 +41,12 @@ namespace CompatBot.Commands var dm = await member.CreateDmChannelAsync().ConfigureAwait(false); await dm.SendMessageAsync($"Only `{Config.CommandPrefix}warn` and `{Config.CommandPrefix}report` are allowed in {ctx.Channel.Mention}").ConfigureAwait(false); } - Config.TelemetryClient?.TrackRequest(ctx.Command.QualifiedName, executionStart, DateTimeOffset.UtcNow-executionStart, HttpStatusCode.Forbidden.ToString(), true); - throw new DSharpPlus.CommandsNext.Exceptions.ChecksFailedException(ctx.Command, ctx, new CheckBaseAttribute[] {new RequiresNotMedia()}); + Config.TelemetryClient?.TrackRequest(ctx.Command.QualifiedName, executionStart, DateTimeOffset.UtcNow - executionStart, HttpStatusCode.Forbidden.ToString(), true); + throw new DSharpPlus.CommandsNext.Exceptions.ChecksFailedException(ctx.Command, ctx, new CheckBaseAttribute[] { new RequiresNotMedia() }); } var disabledCmds = DisabledCommandsProvider.Get(); - if (disabledCmds.Contains(ctx.Command.QualifiedName) && !disabledCmds.Contains("*")) + if (ctx.Command is not null && disabledCmds.Contains(ctx.Command.QualifiedName) && !disabledCmds.Contains("*")) { await ctx.Channel.SendMessageAsync(embed: new DiscordEmbedBuilder {Color = Config.Colors.Maintenance, Description = "Command is currently disabled"}).ConfigureAwait(false); Config.TelemetryClient?.TrackRequest(ctx.Command.QualifiedName, executionStart, DateTimeOffset.UtcNow - executionStart, HttpStatusCode.Locked.ToString(), true); @@ -61,10 +61,12 @@ namespace CompatBot.Commands public override async Task AfterExecutionAsync(CommandContext ctx) { - var qualifiedName = ctx.Command.QualifiedName; - StatsStorage.CmdStatCache.TryGetValue(qualifiedName, out int counter); - StatsStorage.CmdStatCache.Set(qualifiedName, ++counter, StatsStorage.CacheTime); - Config.TelemetryClient?.TrackRequest(qualifiedName, executionStart, DateTimeOffset.UtcNow - executionStart, HttpStatusCode.OK.ToString(), true); + if (ctx.Command?.QualifiedName is string qualifiedName) + { + StatsStorage.CmdStatCache.TryGetValue(qualifiedName, out int counter); + StatsStorage.CmdStatCache.Set(qualifiedName, ++counter, StatsStorage.CacheTime); + Config.TelemetryClient?.TrackRequest(qualifiedName, executionStart, DateTimeOffset.UtcNow - executionStart, HttpStatusCode.OK.ToString(), true); + } if (TriggersTyping(ctx)) await ctx.RemoveReactionAsync(Config.Reactions.PleaseWait).ConfigureAwait(false); @@ -73,6 +75,6 @@ namespace CompatBot.Commands } private static bool TriggersTyping(CommandContext ctx) - => ctx.Command.CustomAttributes.OfType().FirstOrDefault() is TriggersTyping a && a.ExecuteCheck(ctx); + => ctx.Command?.CustomAttributes.OfType().FirstOrDefault() is TriggersTyping a && a.ExecuteCheck(ctx); } } \ No newline at end of file diff --git a/CompatBot/Commands/BotMath.cs b/CompatBot/Commands/BotMath.cs index 278b66c8..16f275e9 100644 --- a/CompatBot/Commands/BotMath.cs +++ b/CompatBot/Commands/BotMath.cs @@ -19,10 +19,11 @@ namespace CompatBot.Commands { try { - - var helpCmd = ctx.CommandsNext.FindCommand("math help", out _); - var helpCtx = ctx.CommandsNext.CreateContext(ctx.Message, ctx.Prefix, helpCmd); - await helpCmd.ExecuteAsync(helpCtx).ConfigureAwait(false); + if (ctx.CommandsNext.FindCommand("math help", out _) is Command helpCmd) + { + var helpCtx = ctx.CommandsNext.CreateContext(ctx.Message, ctx.Prefix, helpCmd); + await helpCmd.ExecuteAsync(helpCtx).ConfigureAwait(false); + } } catch { } return; diff --git a/CompatBot/Commands/CommandsManagement.cs b/CompatBot/Commands/CommandsManagement.cs index 6620b138..871aef96 100644 --- a/CompatBot/Commands/CommandsManagement.cs +++ b/CompatBot/Commands/CommandsManagement.cs @@ -46,7 +46,7 @@ namespace CompatBot.Commands return; } - if (command.StartsWith(ctx.Command.Parent.QualifiedName)) + if (ctx.Command?.Parent is CommandGroup p && command.StartsWith(p.QualifiedName)) { await ctx.ReactWithAsync(Config.Reactions.Failure, "Cannot disable command management commands").ConfigureAwait(false); return; @@ -68,7 +68,7 @@ namespace CompatBot.Commands DisableSubcommands(ctx, c); else DisableSubcommands(ctx, cmd); - if (ctx.Command.Parent.QualifiedName.StartsWith(command)) + if (ctx.Command?.Parent is CommandGroup parent && parent.QualifiedName.StartsWith(command)) await ctx.Channel.SendMessageAsync("Some subcommands cannot be disabled").ConfigureAwait(false); else await ctx.ReactWithAsync(Config.Reactions.Success, $"Disabled `{command}` and all subcommands").ConfigureAwait(false); @@ -174,7 +174,7 @@ namespace CompatBot.Commands private static void DisableSubcommands(CommandContext ctx, Command cmd) { - if (cmd.QualifiedName.StartsWith(ctx.Command.Parent.QualifiedName)) + if (ctx.Command?.Parent is not CommandGroup p || cmd.QualifiedName.StartsWith(p.QualifiedName)) return; DisabledCommandsProvider.Disable(cmd.QualifiedName); @@ -185,7 +185,7 @@ namespace CompatBot.Commands private static void EnableSubcommands(CommandContext ctx, Command cmd) { - if (cmd.QualifiedName.StartsWith(ctx.Command.Parent.QualifiedName)) + if (ctx.Command?.Parent is not CommandGroup p || cmd.QualifiedName.StartsWith(p.QualifiedName)) return; DisabledCommandsProvider.Enable(cmd.QualifiedName); diff --git a/CompatBot/Commands/ContentFilters.cs b/CompatBot/Commands/ContentFilters.cs index 4c92b0e0..3dd4a6cb 100644 --- a/CompatBot/Commands/ContentFilters.cs +++ b/CompatBot/Commands/ContentFilters.cs @@ -102,7 +102,7 @@ namespace CompatBot.Commands public async Task Add(CommandContext ctx, [RemainingText, Description("A plain string to match")] string trigger) { await using var db = new BotDb(); - Piracystring filter; + Piracystring? filter; if (string.IsNullOrEmpty(trigger)) filter = new Piracystring(); else diff --git a/CompatBot/Commands/EventsBaseCommand.cs b/CompatBot/Commands/EventsBaseCommand.cs index 3024aa4a..03073233 100644 --- a/CompatBot/Commands/EventsBaseCommand.cs +++ b/CompatBot/Commands/EventsBaseCommand.cs @@ -104,7 +104,7 @@ namespace CompatBot.Commands } var lastNamedEvent = await db.EventSchedule.OrderByDescending(e => e.End).FirstOrDefaultAsync(e => e.Year == current.Year && e.EventName == eventName).ConfigureAwait(false); - if (lastNamedEvent.End <= currentTicks) + if (lastNamedEvent is not null && lastNamedEvent.End <= currentTicks) { if (lastNamedEvent.End < current.AddMonths(-1).Ticks) { diff --git a/CompatBot/Commands/Fortune.cs b/CompatBot/Commands/Fortune.cs index 7514af7c..a92a0419 100644 --- a/CompatBot/Commands/Fortune.cs +++ b/CompatBot/Commands/Fortune.cs @@ -32,7 +32,7 @@ namespace CompatBot.Commands var prefix = DateTime.UtcNow.ToString("yyyyMMdd")+ user.Id.ToString("x16"); var rng = new Random(prefix.GetStableHash()); await using var db = new ThumbnailDb(); - Database.Fortune fortune; + Database.Fortune? fortune; do { var totalFortunes = await db.Fortune.CountAsync().ConfigureAwait(false); diff --git a/CompatBot/Commands/Pr.cs b/CompatBot/Commands/Pr.cs index 05c38da2..aa9942f9 100644 --- a/CompatBot/Commands/Pr.cs +++ b/CompatBot/Commands/Pr.cs @@ -12,6 +12,7 @@ using DSharpPlus; using DSharpPlus.CommandsNext; using DSharpPlus.CommandsNext.Attributes; using DSharpPlus.Entities; +using TaskStatus = CirrusCiClient.Generated.TaskStatus; namespace CompatBot.Commands { @@ -150,47 +151,48 @@ namespace CompatBot.Commands { bool shouldHaveArtifacts = false; - if (latestBuild.WindowsBuild?.Status is CirrusCiClient.TaskStatus.Completed - || latestBuild.LinuxBuild?.Status is CirrusCiClient.TaskStatus.Completed - || latestBuild.MacBuild?.Status is CirrusCiClient.TaskStatus.Completed) + if ((latestBuild.WindowsBuild?.Status is TaskStatus.Completed + || latestBuild.LinuxBuild?.Status is TaskStatus.Completed + || latestBuild.MacBuild?.Status is TaskStatus.Completed) + && latestBuild.FinishTime.HasValue) { buildTime = $"Built on {latestBuild.FinishTime:u} ({(DateTime.UtcNow - latestBuild.FinishTime.Value).AsTimeDeltaDescription()} ago)"; shouldHaveArtifacts = true; } // Check for subtask errors (win/lin/mac) - if (latestBuild.WindowsBuild?.Status is CirrusCiClient.TaskStatus.Aborted or CirrusCiClient.TaskStatus.Failed or CirrusCiClient.TaskStatus.Skipped) + if (latestBuild.WindowsBuild?.Status is TaskStatus.Aborted or TaskStatus.Failed or TaskStatus.Skipped) { windowsDownloadText = $"❌ {latestBuild.WindowsBuild?.Status}"; } - if (latestBuild.LinuxBuild?.Status is CirrusCiClient.TaskStatus.Aborted or CirrusCiClient.TaskStatus.Failed or CirrusCiClient.TaskStatus.Skipped) + if (latestBuild.LinuxBuild?.Status is TaskStatus.Aborted or TaskStatus.Failed or TaskStatus.Skipped) { linuxDownloadText = $"❌ {latestBuild.LinuxBuild?.Status}"; } - if (latestBuild.MacBuild?.Status is CirrusCiClient.TaskStatus.Aborted or CirrusCiClient.TaskStatus.Failed or CirrusCiClient.TaskStatus.Skipped) + if (latestBuild.MacBuild?.Status is TaskStatus.Aborted or TaskStatus.Failed or TaskStatus.Skipped) { macDownloadText = $"❌ {latestBuild.MacBuild?.Status}"; } // Check estimated time for pending builds - if (latestBuild.WindowsBuild?.Status is CirrusCiClient.TaskStatus.Executing - || latestBuild.LinuxBuild?.Status is CirrusCiClient.TaskStatus.Executing - || latestBuild.MacBuild?.Status is CirrusCiClient.TaskStatus.Executing) + if (latestBuild.WindowsBuild?.Status is TaskStatus.Executing + || latestBuild.LinuxBuild?.Status is TaskStatus.Executing + || latestBuild.MacBuild?.Status is TaskStatus.Executing) { var estimatedCompletionTime = latestBuild.StartTime + (await CirrusCi.GetPipelineDurationAsync(Config.Cts.Token).ConfigureAwait(false)).Mean; var estimatedTime = TimeSpan.FromMinutes(1); if (estimatedCompletionTime > DateTime.UtcNow) estimatedTime = estimatedCompletionTime - DateTime.UtcNow; - if (latestBuild.WindowsBuild?.Status is CirrusCiClient.TaskStatus.Executing) + if (latestBuild.WindowsBuild?.Status is TaskStatus.Executing) { windowsDownloadText = $"⏳ Pending in {estimatedTime.AsTimeDeltaDescription()}..."; } - if (latestBuild.LinuxBuild?.Status is CirrusCiClient.TaskStatus.Executing) + if (latestBuild.LinuxBuild?.Status is TaskStatus.Executing) { linuxDownloadText = $"⏳ Pending in {estimatedTime.AsTimeDeltaDescription()}..."; } - if (latestBuild.MacBuild?.Status is CirrusCiClient.TaskStatus.Executing) + if (latestBuild.MacBuild?.Status is TaskStatus.Executing) { macDownloadText = $"⏳ Pending in {estimatedTime.AsTimeDeltaDescription()}..."; } diff --git a/CompatBot/Commands/Warnings.cs b/CompatBot/Commands/Warnings.cs index 9e09051c..a49cdf77 100644 --- a/CompatBot/Commands/Warnings.cs +++ b/CompatBot/Commands/Warnings.cs @@ -166,7 +166,7 @@ namespace CompatBot.Commands { await using var db = new BotDb(); var warn = await db.Warning.FirstOrDefaultAsync(w => w.Id == id).ConfigureAwait(false); - if (warn.Retracted) + if (warn?.Retracted is true) { warn.Retracted = false; warn.RetractedBy = null; diff --git a/CompatBot/Database/NamingConventionConverter.cs b/CompatBot/Database/NamingConventionConverter.cs index 254cb134..d8bb13bd 100644 --- a/CompatBot/Database/NamingConventionConverter.cs +++ b/CompatBot/Database/NamingConventionConverter.cs @@ -12,15 +12,19 @@ namespace CompatBot.Database foreach (var entity in modelBuilder.Model.GetEntityTypes()) { - entity.SetTableName(nameResolver(entity.GetTableName())); + if (entity.GetTableName() is string tableName) + entity.SetTableName(nameResolver(tableName)); foreach (var property in entity.GetProperties()) property.SetColumnName(nameResolver(property.Name)); foreach (var key in entity.GetKeys()) - key.SetName(nameResolver(key.GetName())); + if (key.GetName() is string name) + key.SetName(nameResolver(name)); foreach (var key in entity.GetForeignKeys()) - key.SetConstraintName(nameResolver(key.GetConstraintName())); + if (key.GetConstraintName() is string constraint) + key.SetConstraintName(nameResolver(constraint)); foreach (var index in entity.GetIndexes()) - index.SetDatabaseName(nameResolver(index.GetDatabaseName())); + if (index.GetDatabaseName() is string dbName) + index.SetDatabaseName(nameResolver(dbName)); } } } diff --git a/CompatBot/EventHandlers/UnknownCommandHandler.cs b/CompatBot/EventHandlers/UnknownCommandHandler.cs index b8683ae4..207f2d44 100644 --- a/CompatBot/EventHandlers/UnknownCommandHandler.cs +++ b/CompatBot/EventHandlers/UnknownCommandHandler.cs @@ -34,7 +34,7 @@ namespace CompatBot.EventHandlers var ex = e.Exception; if (ex is InvalidOperationException && ex.Message.Contains("No matching subcommands were found")) - ex = new CommandNotFoundException(e.Command.Name); + ex = new CommandNotFoundException(e.Command?.Name ?? "unknown command name"); if (ex is not CommandNotFoundException cnfe) { diff --git a/CompatBot/Utils/Extensions/CommandContextExtensions.cs b/CompatBot/Utils/Extensions/CommandContextExtensions.cs index 396a7503..6731f61d 100644 --- a/CompatBot/Utils/Extensions/CommandContextExtensions.cs +++ b/CompatBot/Utils/Extensions/CommandContextExtensions.cs @@ -27,7 +27,7 @@ namespace CompatBot.Utils } public static async Task CreateDmAsync(this CommandContext ctx) - => ctx.Channel.IsPrivate ? ctx.Channel : await ctx.Member.CreateDmChannelAsync().ConfigureAwait(false); + => ctx.Channel.IsPrivate || ctx.Member is null ? ctx.Channel : await ctx.Member.CreateDmChannelAsync().ConfigureAwait(false); public static Task GetChannelForSpamAsync(this CommandContext ctx) => LimitedToSpamChannel.IsSpamChannel(ctx.Channel) ? Task.FromResult(ctx.Channel) : ctx.CreateDmAsync();