clean up some warnings

This commit is contained in:
13xforever 2022-06-20 17:14:32 +05:00
parent 76e14e30d9
commit 079dcbcc5c
24 changed files with 75 additions and 52 deletions

View File

@ -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
}
}
}

View File

@ -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;

View File

@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<EmitCompilerGeneratedFiles>false</EmitCompilerGeneratedFiles>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\CompatApiClient\CompatApiClient.csproj" />

View File

@ -1,4 +1,5 @@
using System;
using CirrusCiClient.Generated;
namespace CirrusCiClient.POCOs
{

View File

@ -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(), },
};

View File

@ -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,
};
}

View File

@ -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,
};
}

View File

@ -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,
};
}

View File

@ -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);

View File

@ -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,
};
}

View File

@ -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;
}
}

View File

@ -14,9 +14,12 @@ namespace CompatBot.Commands.Attributes
{
public override async Task<bool> 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);

View File

@ -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);

View File

@ -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<TriggersTyping>().FirstOrDefault() is TriggersTyping a && a.ExecuteCheck(ctx);
=> ctx.Command?.CustomAttributes.OfType<TriggersTyping>().FirstOrDefault() is TriggersTyping a && a.ExecuteCheck(ctx);
}
}

View File

@ -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;

View File

@ -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);

View File

@ -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

View File

@ -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)
{

View File

@ -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);

View File

@ -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()}...";
}

View File

@ -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;

View File

@ -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));
}
}
}

View File

@ -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)
{

View File

@ -27,7 +27,7 @@ namespace CompatBot.Utils
}
public static async Task<DiscordChannel> 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<DiscordChannel> GetChannelForSpamAsync(this CommandContext ctx)
=> LimitedToSpamChannel.IsSpamChannel(ctx.Channel) ? Task.FromResult(ctx.Channel) : ctx.CreateDmAsync();