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

@@ -73,7 +73,7 @@ public partial class Gambling
{
try
{
if (_msg != null)
if (_msg is not null)
{
var _ = _msg.DeleteAsync();
}
@@ -97,7 +97,7 @@ public partial class Gambling
.WithTitle("BlackJack")
.AddField($"{dealerIcon} Dealer's Hand | Value: {bj.Dealer.GetHandValue()}", cStr);
if (bj.CurrentUser != null) embed.WithFooter($"Player to make a choice: {bj.CurrentUser.DiscordUser}");
if (bj.CurrentUser is not null) embed.WithFooter($"Player to make a choice: {bj.CurrentUser.DiscordUser}");
foreach (var p in bj.Players)
{

View File

@@ -140,7 +140,7 @@ public class Blackjack
{
var cu = CurrentUser;
if (cu != null && cu.DiscordUser == u)
if (cu is not null && cu.DiscordUser == u)
return await Stand(cu);
return false;
@@ -221,7 +221,7 @@ public class Blackjack
{
var cu = CurrentUser;
if (cu != null && cu.DiscordUser == u)
if (cu is not null && cu.DiscordUser == u)
return await Double(cu);
return false;
@@ -268,7 +268,7 @@ public class Blackjack
{
var cu = CurrentUser;
if (cu != null && cu.DiscordUser == u)
if (cu is not null && cu.DiscordUser == u)
return await Hit(cu);
return false;

View File

@@ -78,8 +78,8 @@ public class GameStatusEvent : ICurrencyEvent
try
{
await _cs.AddBulkAsync(toAward,
toAward.Select(x => "GameStatus Event"),
toAward.Select(x => _amount),
toAward.Select(_ => "GameStatus Event"),
toAward.Select(_ => _amount),
true);
if (_isPotLimited)

View File

@@ -73,7 +73,7 @@ public class ReactionEvent : ICurrencyEvent
try
{
await _cs.AddBulkAsync(toAward, toAward.Select(x => "Reaction Event"), toAward.Select(x => _amount), true);
await _cs.AddBulkAsync(toAward, toAward.Select(_ => "Reaction Event"), toAward.Select(_ => _amount), true);
if (_isPotLimited)
await _msg.ModifyAsync(m =>

View File

@@ -133,7 +133,7 @@ public sealed class Connect4Game : IDisposable
}
CurrentPhase = Phase.P1Move; //start the game
_playerTimeoutTimer = new(async state =>
_playerTimeoutTimer = new(async _ =>
{
await _locker.WaitAsync();
try
@@ -347,7 +347,7 @@ public sealed class Connect4Game : IDisposable
return;
}
if (winId != null)
if (winId is not null)
_cs.AddAsync(winId.Value, "Connnect4-win", (long)(_options.Bet * 1.98), true);
}

View File

@@ -38,7 +38,7 @@ public partial class Gambling
var res = await _service.JoinOrCreateGame(ctx.Channel.Id, ctx.User, amount, mixed, OnEnded);
if (res.Item1 != null)
if (res.Item1 is not null)
{
await SendConfirmAsync(GetText(strs.rafflecur(res.Item1.GameType.ToString())),
string.Join("\n", res.Item1.Users.Select(x => $"{x.DiscordUser} ({x.Amount})")),

View File

@@ -22,7 +22,7 @@ public partial class Gambling
if (num is < 1 or > 10)
throw new ArgumentOutOfRangeException(nameof(num));
var cards = guildId is null ? new() : _allDecks.GetOrAdd(ctx.Guild, s => new());
var cards = guildId is null ? new() : _allDecks.GetOrAdd(ctx.Guild, _ => new());
var images = new List<Image<Rgba32>>();
var cardObjects = new List<Deck.Card>();
for (var i = 0; i < num; i++)
@@ -53,7 +53,7 @@ public partial class Gambling
if (cardObjects.Count == 5)
toSend += $" drew `{Deck.GetHandValue(cardObjects)}`";
if (guildId != null)
if (guildId is not null)
toSend += "\n" + GetText(strs.cards_left(Format.Bold(cards.CardPool.Count.ToString())));
return (img.ToStream(), toSend);
@@ -97,8 +97,8 @@ public partial class Gambling
//var channel = (ITextChannel)ctx.Channel;
_allDecks.AddOrUpdate(ctx.Guild,
g => new(),
(g, c) =>
_ => new(),
(_, c) =>
{
c.Restart();
return c;

View File

@@ -110,7 +110,7 @@ public partial class Gambling : GamblingModule<GamblingService>
}
TimeSpan? rem;
if ((rem = _cache.AddTimelyClaim(ctx.User.Id, period)) != null)
if ((rem = _cache.AddTimelyClaim(ctx.User.Id, period)) is not null)
{
await ReplyErrorLocalizedAsync(strs.timely_already_claimed(rem?.ToString(@"dd\d\ hh\h\ mm\m\ ss\s")));
return;
@@ -308,8 +308,8 @@ public partial class Gambling : GamblingModule<GamblingService>
var users = (await ctx.Guild.GetUsersAsync()).Where(u => u.GetRoles().Contains(role)).ToList();
await _cs.AddBulkAsync(users.Select(x => x.Id),
users.Select(x => $"Awarded by bot owner to **{role.Name}** role. ({ctx.User.Username}/{ctx.User.Id})"),
users.Select(x => amount),
users.Select(_ => $"Awarded by bot owner to **{role.Name}** role. ({ctx.User.Username}/{ctx.User.Id})"),
users.Select(_ => amount),
true);
await ReplyConfirmLocalizedAsync(strs.mass_award(n(amount),
@@ -326,8 +326,8 @@ public partial class Gambling : GamblingModule<GamblingService>
var users = (await role.GetMembersAsync()).ToList();
await _cs.RemoveBulkAsync(users.Select(x => x.Id),
users.Select(x => $"Taken by bot owner from **{role.Name}** role. ({ctx.User.Username}/{ctx.User.Id})"),
users.Select(x => amount),
users.Select(_ => $"Taken by bot owner from **{role.Name}** role. ({ctx.User.Username}/{ctx.User.Id})"),
users.Select(_ => amount),
true);
await ReplyConfirmLocalizedAsync(strs.mass_take(n(amount),
@@ -532,7 +532,7 @@ public partial class Gambling : GamblingModule<GamblingService>
await _tracker.EnsureUsersDownloadedAsync(ctx.Guild);
var sg = (SocketGuild)ctx.Guild;
cleanRichest = cleanRichest.Where(x => sg.GetUser(x.UserId) != null).ToList();
cleanRichest = cleanRichest.Where(x => sg.GetUser(x.UserId) is not null).ToList();
}
else
{

View File

@@ -89,7 +89,7 @@ public partial class Gambling
var enabledIn = _service.GetAllGeneratingChannels();
return ctx.SendPaginatedConfirmAsync(page,
cur =>
_ =>
{
var items = enabledIn.Skip(page * 9).Take(9);

View File

@@ -81,7 +81,7 @@ public class PlantPickService : INService
else
{
var toDelete = guildConfig.GenerateCurrencyChannelIds.FirstOrDefault(x => x.Equals(toAdd));
if (toDelete != null) uow.Remove(toDelete);
if (toDelete is not null) uow.Remove(toDelete);
_generationChannels.TryRemove(cid);
enabled = false;
}

View File

@@ -66,7 +66,7 @@ public class VoteRewardService : INService, IReadyExecutor
await _currencyService.AddBulkAsync(ids,
data.Select(_ => "top.gg vote reward"),
data.Select(x => _gamb.Data.VoteReward),
data.Select(_ => _gamb.Data.VoteReward),
true);
Log.Information("Rewarding {Count} top.gg voters", ids.Count());
@@ -95,7 +95,7 @@ public class VoteRewardService : INService, IReadyExecutor
await _currencyService.AddBulkAsync(ids,
data.Select(_ => "discords.com vote reward"),
data.Select(x => _gamb.Data.VoteReward),
data.Select(_ => _gamb.Data.VoteReward),
true);
Log.Information("Rewarding {Count} discords.com voters", ids.Count());

View File

@@ -125,7 +125,7 @@ public class WaifuService : INService
//wives stay though
uow.SaveChanges();
await uow.SaveChangesAsync();
return true;
}
@@ -236,7 +236,7 @@ public class WaifuService : INService
}
else
{
if (w.Affinity != null)
if (w.Affinity is not null)
oldAff = w.Affinity;
w.Affinity = newAff;
success = true;
@@ -270,11 +270,10 @@ public class WaifuService : INService
DivorceResult result;
TimeSpan? remaining = null;
long amount = 0;
WaifuInfo w = null;
WaifuInfo w;
await using (var uow = _db.GetDbContext())
{
w = uow.WaifuInfo.ByWaifuUserId(targetId);
var now = DateTime.UtcNow;
if (w?.Claimer is null || w.Claimer.UserId != user.Id)
{
result = DivorceResult.NotYourWife;
@@ -373,7 +372,7 @@ public class WaifuService : INService
public WaifuInfoStats GetFullWaifuInfoAsync(IGuildUser target)
{
using var uow = _db.GetDbContext();
var du = uow.GetOrCreateUser(target);
_ = uow.GetOrCreateUser(target);
return GetFullWaifuInfoAsync(target.Id);
}

View File

@@ -181,7 +181,7 @@ public partial class Gambling
.ThenInclude(x => x.Items))
.ShopEntries);
entry = entries.ElementAtOrDefault(index);
if (entry != null)
if (entry is not null)
if (entry.Items.Add(item))
uow.SaveChanges();
}
@@ -281,7 +281,7 @@ public partial class Gambling
.ThenInclude(x => x.Items))
.ShopEntries);
entry = entries.ElementAtOrDefault(index);
if (entry != null && (rightType = entry.Type == ShopEntryType.List))
if (entry is not null && (rightType = entry.Type == ShopEntryType.List))
if (added = entry.Items.Add(item))
uow.SaveChanges();
}
@@ -312,7 +312,7 @@ public partial class Gambling
var entries = new IndexedCollection<ShopEntry>(config.ShopEntries);
removed = entries.ElementAtOrDefault(index);
if (removed != null)
if (removed is not null)
{
uow.RemoveRange(removed.Items);
uow.Remove(removed);

View File

@@ -159,7 +159,7 @@ public partial class Gambling
var (oldAff, sucess, remaining) = await _service.ChangeAffinityAsync(ctx.User, u);
if (!sucess)
{
if (remaining != null)
if (remaining is not null)
await ReplyErrorLocalizedAsync(strs.waifu_affinity_cooldown(
Format.Bold(((int)remaining?.TotalHours).ToString()),
Format.Bold(remaining?.Minutes.ToString())));