- More code cleanup and codestyle updates

- Fixed some possible nullref exceptions
- Methods signatures now have up to 3 parameters before breakaing down each parameter in a separate line
- Method invocations have the same rule, except the first parameter will be in the same line as the invocation to prevent some ugliness when passing lambas as arguments
- Applied many more codestyles
- Extensions folder fully reformatted
This commit is contained in:
Kwoth
2021-12-26 17:28:39 +01:00
parent b85ba177cd
commit d5fd6aae8e
217 changed files with 1017 additions and 1494 deletions

View File

@@ -18,14 +18,10 @@ public class AnimalRacingUser
}
public override bool Equals(object obj)
{
return obj is AnimalRacingUser x
=> obj is AnimalRacingUser x
? x.UserId == this.UserId
: false;
}
public override int GetHashCode()
{
return this.UserId.GetHashCode();
}
=> this.UserId.GetHashCode();
}

View File

@@ -9,7 +9,7 @@ public class RaceOptions : INadekoCommandOptions
public void NormalizeOptions()
{
if (this.StartTime < 10 || this.StartTime > 120)
if (this.StartTime is < 10 or > 120)
this.StartTime = 20;
}
}

View File

@@ -203,7 +203,7 @@ public class Blackjack
{
foreach (var usr in Players)
{
if (usr.State == User.UserState.Stand || usr.State == User.UserState.Blackjack)
if (usr.State is User.UserState.Stand or User.UserState.Blackjack)
usr.State = User.UserState.Won;
else
usr.State = User.UserState.Lost;
@@ -226,7 +226,7 @@ public class Blackjack
foreach (var usr in Players)
{
if (usr.State == User.UserState.Won || usr.State == User.UserState.Blackjack)
if (usr.State is User.UserState.Won or User.UserState.Blackjack)
{
await _cs.AddAsync(usr.DiscordUser.Id, "BlackJack-win", usr.Bet * 2, gamble: true).ConfigureAwait(false);
}

View File

@@ -20,9 +20,7 @@ public abstract class Player
}
public int GetRawHandValue()
{
return Cards.Sum(x => x.Number == 1 ? 11 : x.Number >= 10 ? 10 : x.Number);
}
=> Cards.Sum(x => x.Number == 1 ? 11 : x.Number >= 10 ? 10 : x.Number);
}
public class Dealer : Player

View File

@@ -13,16 +13,12 @@ public class CurrencyRaffleGame
public long Amount { get; set; }
public override int GetHashCode()
{
return DiscordUser.GetHashCode();
}
=> DiscordUser.GetHashCode();
public override bool Equals(object obj)
{
return obj is User u
=> obj is User u
? u.DiscordUser == DiscordUser
: false;
}
}
private readonly HashSet<User> _users = new();
@@ -30,9 +26,7 @@ public class CurrencyRaffleGame
public Type GameType { get; }
public CurrencyRaffleGame(Type type)
{
GameType = type;
}
=> GameType = type;
public bool AddUser(IUser usr, long amount)
{

View File

@@ -166,13 +166,11 @@ public class Deck
/// Creates a new instance of the BlackJackGame, this allows you to create multiple games running at one time.
/// </summary>
public Deck()
{
RefillPool();
}
=> RefillPool();
static Deck()
{
InitHandValues();
}
=> InitHandValues();
/// <summary>
/// Restart the game of blackjack. It will only refill the pool for now. Probably wont be used, unless you want to have only 1 bjg running at one time,
/// then you will restart the same game every time.

View File

@@ -1,5 +1,4 @@
using NadekoBot.Common.Collections;
using NadekoBot.Services.Database.Models;
using NadekoBot.Services.Database.Models;
namespace NadekoBot.Modules.Gambling.Common.Events;
@@ -115,9 +114,7 @@ public class GameStatusEvent : ICurrencyEvent
}
private IEmbedBuilder GetEmbed(long pot)
{
return _embedFunc(CurrencyEvent.Type.GameStatus, _opts, pot);
}
=> _embedFunc(CurrencyEvent.Type.GameStatus, _opts, pot);
private async Task OnMessageDeleted(Cacheable<IMessage, ulong> msg, Cacheable<IMessageChannel, ulong> cacheable)
{

View File

@@ -1,5 +1,4 @@
using NadekoBot.Common.Collections;
using NadekoBot.Services.Database.Models;
using NadekoBot.Services.Database.Models;
namespace NadekoBot.Modules.Gambling.Common.Events;
@@ -118,9 +117,7 @@ public class ReactionEvent : ICurrencyEvent
}
private IEmbedBuilder GetEmbed(long pot)
{
return _embedFunc(CurrencyEvent.Type.Reaction, _opts, pot);
}
=> _embedFunc(CurrencyEvent.Type.Reaction, _opts, pot);
private async Task OnMessageDeleted(Cacheable<IMessage, ulong> msg, Cacheable<IMessageChannel, ulong> cacheable)
{

View File

@@ -105,14 +105,12 @@ Doesn't have to be ordered.")]
public BetRollPair[] Pairs { get; set; } = Array.Empty<BetRollPair>();
public BetRollConfig()
{
Pairs = new BetRollPair[]
=> Pairs = new BetRollPair[]
{
new() { WhenAbove = 99, MultiplyBy = 10 },
new() { WhenAbove = 90, MultiplyBy = 4 },
new() { WhenAbove = 66, MultiplyBy = 2 }
};
}
}
[Cloneable]
@@ -163,8 +161,7 @@ public partial class WheelOfFortuneSettings
public decimal[] Multipliers { get; set; }
public WheelOfFortuneSettings()
{
Multipliers = new decimal[]
=> Multipliers = new decimal[]
{
1.7M,
1.5M,
@@ -175,7 +172,6 @@ public partial class WheelOfFortuneSettings
1.2M,
2.4M,
};
}
}
[Cloneable]
@@ -191,8 +187,7 @@ If negative is true, gift will instead reduce waifu value.")]
public List<WaifuItemModel> Items { get; set; } = new();
public WaifuConfig()
{
Items = new()
=> Items = new()
{
new("🥔", 5, "Potato"),
new("🍪", 10, "Cookie"),
@@ -231,7 +226,6 @@ If negative is true, gift will instead reduce waifu value.")]
new("🚀", 30000, "Spaceship"),
new("🌕", 50000, "Moon")
};
}
}
[Cloneable]

View File

@@ -10,9 +10,7 @@ public abstract class GamblingModule<TService> : NadekoModule<TService>
protected string CurrencyName => _config.Currency.Name;
protected GamblingModule(GamblingConfigService gambService)
{
_lazyConfig = new(() => gambService.Data);
}
=> _lazyConfig = new(() => gambService.Data);
private async Task<bool> InternalCheckBet(long amount)
{