Using pattern matching for nulls where applicable, discarded unused lambda parameters, cleaned up some classes. Unignored ServerLog commands which was mistakenly ignored due to a .gitignore rule

This commit is contained in:
Kwoth
2022-01-01 08:44:51 +01:00
parent f81f9fadd3
commit 9b4eb21321
91 changed files with 1591 additions and 224 deletions

View File

@@ -54,7 +54,7 @@ public partial class Utility
var config = uow.GuildConfigsForId(ctx.Guild.Id, set => set.Include(x => x.CommandAliases));
var toAdd = new CommandAlias { Mapping = mapping, Trigger = trigger };
var tr = config.CommandAliases.FirstOrDefault(x => x.Trigger == trigger);
if (tr != null)
if (tr is not null)
uow.Set<CommandAlias>().Remove(tr);
uow.SaveChanges();
}
@@ -91,7 +91,7 @@ public partial class Utility
uow.SaveChanges();
}
map.AddOrUpdate(trigger, mapping, (key, old) => mapping);
map.AddOrUpdate(trigger, mapping, (_, _) => mapping);
return map;
});

View File

@@ -103,7 +103,7 @@ public partial class Utility
.WithOkColor();
var av = user.RealAvatarUrl();
if (av != null && av.IsAbsoluteUri)
if (av is not null && av.IsAbsoluteUri)
embed.WithThumbnailUrl(av.ToString());
await ctx.Channel.EmbedAsync(embed);
}

View File

@@ -83,7 +83,7 @@ public partial class Utility
await using (var uow = _db.GetDbContext())
{
quote = await uow.Quotes.GetRandomQuoteByKeywordAsync(ctx.Guild.Id, keyword);
//if (quote != null)
//if (quote is not null)
//{
// quote.UseCount += 1;
// uow.Complete();

View File

@@ -181,7 +181,7 @@ public partial class Utility
if (ts > TimeSpan.FromDays(60))
return false;
if (ctx.Guild != null)
if (ctx.Guild is not null)
{
var perms = ((IGuildUser)ctx.User).GetPermissions((IGuildChannel)ctx.Channel);
if (!perms.MentionEveryone) message = message.SanitizeAllMentions();

View File

@@ -102,7 +102,7 @@ public partial class Utility
interval?.Time ?? (startTimeOfDay is null ? TimeSpan.FromMinutes(5) : TimeSpan.FromDays(1));
if (string.IsNullOrWhiteSpace(message)
|| (interval != null
|| (interval is not null
&& (interval.Time > TimeSpan.FromMinutes(25000) || interval.Time < TimeSpan.FromMinutes(1))))
return;

View File

@@ -56,7 +56,7 @@ public class CommandMapService : IInputTransformer, INService
if (guild is null || string.IsNullOrWhiteSpace(input))
return input;
if (guild != null)
if (guild is not null)
if (AliasMaps.TryGetValue(guild.Id, out var maps))
{
var keys = maps.Keys.OrderByDescending(x => x.Length);

View File

@@ -212,7 +212,7 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};")
try
{
var lastMsgInChannel = await channel.GetMessagesAsync(2).Flatten().FirstAsync();
if (lastMsgInChannel != null && lastMsgInChannel.Id == repeater.LastMessageId)
if (lastMsgInChannel is not null && lastMsgInChannel.Id == repeater.LastMessageId)
return;
}
catch (Exception ex)
@@ -228,7 +228,7 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};")
try
{
var oldMsg = await channel.GetMessageAsync(lastMessageId);
if (oldMsg != null) await oldMsg.DeleteAsync();
if (oldMsg is not null) await oldMsg.DeleteAsync();
}
catch (Exception ex)
{

View File

@@ -21,7 +21,7 @@ public sealed class RunningRepeater
private DateTime CalculateInitialExecution()
{
if (Repeater.StartTimeOfDay != null)
if (Repeater.StartTimeOfDay is not null)
{
// if there was a start time of day
// calculate whats the next time of day repeat should trigger at

View File

@@ -77,7 +77,7 @@ public class StreamRoleService : INService
if (action == AddRemove.Rem)
{
var toDelete = streamRoleSettings.Whitelist.FirstOrDefault(x => x.Equals(userObj));
if (toDelete != null)
if (toDelete is not null)
{
uow.Remove(toDelete);
success = true;
@@ -95,7 +95,7 @@ public class StreamRoleService : INService
if (action == AddRemove.Rem)
{
var toRemove = streamRoleSettings.Blacklist.FirstOrDefault(x => x.Equals(userObj));
if (toRemove != null)
if (toRemove is not null)
{
success = true;
success = streamRoleSettings.Blacklist.Remove(toRemove);
@@ -299,5 +299,5 @@ public class StreamRoleService : INService
}
private void UpdateCache(ulong guildId, StreamRoleSettings setting)
=> guildSettings.AddOrUpdate(guildId, key => setting, (key, old) => setting);
=> guildSettings.AddOrUpdate(guildId, _ => setting, (_, _) => setting);
}

View File

@@ -90,7 +90,7 @@ public partial class Utility : NadekoModule
.Where(u => u.Activities.FirstOrDefault()?.Name?.ToUpperInvariant()
== game)
.Select(u => u.Username)
.OrderBy(x => rng.Next())
.OrderBy(_ => rng.Next())
.Take(60)
.ToArray());
@@ -100,7 +100,7 @@ public partial class Utility : NadekoModule
else
await SendConfirmAsync("```css\n"
+ string.Join("\n",
arr.GroupBy(item => i++ / 2)
arr.GroupBy(_ => i++ / 2)
.Select(ig => string.Concat(ig.Select(el => $"• {el,-27}"))))
+ "\n```");
}
@@ -198,7 +198,7 @@ public partial class Utility : NadekoModule
if (page is < 1 or > 100)
return;
if (target != null)
if (target is not null)
{
var roles = target.GetRoles()
.Except(new[] { guild.EveryoneRole })