More target-typed new and redundant paranthesis cleanup

This commit is contained in:
Kwoth
2021-12-20 00:33:11 +01:00
parent 345a9e9524
commit 1b2017024c
152 changed files with 573 additions and 580 deletions

View File

@@ -38,7 +38,7 @@ public sealed class AnimalRace : IDisposable
{
this._currency = currency;
this._options = options;
this._animalsQueue = new Queue<RaceAnimal>(availableAnimals);
this._animalsQueue = new(availableAnimals);
this.MaxUsers = _animalsQueue.Count;
if (this._animalsQueue.Count == 0)

View File

@@ -16,7 +16,7 @@ public class Betroll
public Betroll(BetRollConfig settings)
{
_thresholdPairs = settings.Pairs.OrderByDescending(x => x.WhenAbove);
_rng = new Random();
_rng = new();
}
public Result Roll()
@@ -26,14 +26,14 @@ public class Betroll
var pair = _thresholdPairs.FirstOrDefault(x => x.WhenAbove < roll);
if (pair is null)
{
return new Result
return new()
{
Multiplier = 0,
Roll = roll,
};
}
return new Result
return new()
{
Multiplier = pair.MultiplyBy,
Roll = roll,

View File

@@ -35,7 +35,7 @@ public class Blackjack
{
_cs = cs;
_db = db;
Dealer = new Dealer();
Dealer = new();
}
public void Start()
@@ -105,7 +105,7 @@ public class Blackjack
{
var pause = Task.Delay(20000); //10 seconds to decide
CurrentUser = usr;
_currentUserMove = new TaskCompletionSource<bool>();
_currentUserMove = new();
await PrintState().ConfigureAwait(false);
// either wait for the user to make an action and
// if he doesn't - stand
@@ -134,7 +134,7 @@ public class Blackjack
return false;
}
Players.Add(new User(user, bet));
Players.Add(new(user, bet));
var _ = PrintState();
return true;
}

View File

@@ -45,7 +45,7 @@ public class CurrencyRaffleGame
_users.First().Amount != amount)
return false;
if (!_users.Add(new User
if (!_users.Add(new()
{
DiscordUser = usr,
Amount = amount,

View File

@@ -7,15 +7,15 @@ public class QuadDeck : Deck
{
protected override void RefillPool()
{
CardPool = new List<Card>(52 * 4);
CardPool = new(52 * 4);
for (var j = 1; j < 14; j++)
{
for (var i = 1; i < 5; i++)
{
CardPool.Add(new Card((CardSuit)i, j));
CardPool.Add(new Card((CardSuit)i, j));
CardPool.Add(new Card((CardSuit)i, j));
CardPool.Add(new Card((CardSuit)i, j));
CardPool.Add(new((CardSuit)i, j));
CardPool.Add(new((CardSuit)i, j));
CardPool.Add(new((CardSuit)i, j));
CardPool.Add(new((CardSuit)i, j));
}
}
}
@@ -60,7 +60,7 @@ public class Deck
{
var str = string.Empty;
if (Number <= 10 && Number > 1)
if (Number is <= 10 and > 1)
{
str += "_" + Number;
}
@@ -101,7 +101,7 @@ public class Deck
throw new ArgumentException("Invalid input", nameof(input));
}
return new Card(s, n);
return new(s, n);
}
public string GetEmojiString()
@@ -189,7 +189,7 @@ public class Deck
/// </summary>
protected virtual void RefillPool()
{
CardPool = new List<Card>(52);
CardPool = new(52);
//foreach suit
for (var j = 1; j < 14; j++)
{
@@ -199,7 +199,7 @@ public class Deck
//generate a card of that suit and number and add it to the pool
// the pool will go from ace of spades,hears,diamonds,clubs all the way to the king of spades. hearts, ...
CardPool.Add(new Card((CardSuit)i, j));
CardPool.Add(new((CardSuit)i, j));
}
}
}
@@ -256,7 +256,7 @@ public class Deck
- cards.Min(card => (int)card.Number) == 4);
if (toReturn || cards.All(c => c.Number != 1)) return toReturn;
var newCards = cards.Select(c => c.Number == 1 ? new Card(c.Suit, 14) : c);
var newCards = cards.Select(c => c.Number == 1 ? new(c.Suit, 14) : c);
return (newCards.Max(card => (int)card.Number)
- newCards.Min(card => (int)card.Number) == 4);
}
@@ -281,7 +281,7 @@ public class Deck
bool isStraightFlush(List<Card> cards) => hasStraightFlush(cards) && !isRoyalFlush(cards);
handValues = new Dictionary<string, Func<List<Card>, bool>>
handValues = new()
{
{ "Royal Flush", isRoyalFlush },
{ "Straight Flush", isStraightFlush },

View File

@@ -54,12 +54,12 @@ public class GameStatusEvent : ICurrencyEvent
_channel = ch;
_opts = opt;
// generate code
_code = new string(_sneakyGameStatusChars.Shuffle().Take(5).ToArray());
_code = new(_sneakyGameStatusChars.Shuffle().Take(5).ToArray());
_t = new Timer(OnTimerTick, null, Timeout.InfiniteTimeSpan, TimeSpan.FromSeconds(2));
_t = new(OnTimerTick, null, Timeout.InfiniteTimeSpan, TimeSpan.FromSeconds(2));
if (_opts.Hours > 0)
{
_timeout = new Timer(EventTimeout, null, TimeSpan.FromHours(_opts.Hours), Timeout.InfiniteTimeSpan);
_timeout = new(EventTimeout, null, TimeSpan.FromHours(_opts.Hours), Timeout.InfiniteTimeSpan);
}
}
@@ -92,7 +92,7 @@ public class GameStatusEvent : ICurrencyEvent
await _msg.ModifyAsync(m =>
{
m.Embed = GetEmbed(PotSize).Build();
}, new RequestOptions() { RetryMode = RetryMode.AlwaysRetry }).ConfigureAwait(false);
}, new() { RetryMode = RetryMode.AlwaysRetry }).ConfigureAwait(false);
}
Log.Information("Awarded {0} users {1} currency.{2}",
@@ -175,7 +175,7 @@ public class GameStatusEvent : ICurrencyEvent
try
{
await msg.DeleteAsync(new RequestOptions()
await msg.DeleteAsync(new()
{
RetryMode = RetryMode.AlwaysFail
});

View File

@@ -52,10 +52,10 @@ public class ReactionEvent : ICurrencyEvent
_opts = opt;
_config = config;
_t = new Timer(OnTimerTick, null, Timeout.InfiniteTimeSpan, TimeSpan.FromSeconds(2));
_t = new(OnTimerTick, null, Timeout.InfiniteTimeSpan, TimeSpan.FromSeconds(2));
if (_opts.Hours > 0)
{
_timeout = new Timer(EventTimeout, null, TimeSpan.FromHours(_opts.Hours), Timeout.InfiniteTimeSpan);
_timeout = new(EventTimeout, null, TimeSpan.FromHours(_opts.Hours), Timeout.InfiniteTimeSpan);
}
}
@@ -88,7 +88,7 @@ public class ReactionEvent : ICurrencyEvent
await _msg.ModifyAsync(m =>
{
m.Embed = GetEmbed(PotSize).Build();
}, new RequestOptions() { RetryMode = RetryMode.AlwaysRetry }).ConfigureAwait(false);
}, new() { RetryMode = RetryMode.AlwaysRetry }).ConfigureAwait(false);
}
Log.Information("Awarded {0} users {1} currency.{2}",

View File

@@ -11,15 +11,15 @@ public sealed partial class GamblingConfig : ICloneable<GamblingConfig>
{
public GamblingConfig()
{
BetRoll = new BetRollConfig();
WheelOfFortune = new WheelOfFortuneSettings();
Waifu = new WaifuConfig();
Currency = new CurrencyConfig();
BetFlip = new BetFlipConfig();
Generation = new GenerationConfig();
Timely = new TimelyConfig();
Decay = new DecayConfig();
Slots = new SlotsConfig();
BetRoll = new();
WheelOfFortune = new();
Waifu = new();
Currency = new();
BetFlip = new();
Generation = new();
Timely = new();
Decay = new();
Slots = new();
}
[Comment(@"DO NOT CHANGE")]

View File

@@ -13,7 +13,7 @@ public abstract class GamblingModule<TService> : NadekoModule<TService>
protected GamblingModule(GamblingConfigService gambService)
{
_lazyConfig = new Lazy<GamblingConfig>(() => gambService.Data);
_lazyConfig = new(() => gambService.Data);
}
private async Task<bool> InternalCheckBet(long amount)

View File

@@ -49,7 +49,7 @@ public class RollDuelGame
this.Amount = amount;
_cs = cs;
_timeoutTimer = new Timer(async delegate
_timeoutTimer = new(async delegate
{
await _locker.WaitAsync().ConfigureAwait(false);
try

View File

@@ -36,6 +36,6 @@ public class SlotGame
else if (rolls.Any(x => x == 5))
multi = 1;
return new Result(multi, rolls);
return new(multi, rolls);
}
}

View File

@@ -20,7 +20,7 @@ public class WheelOfFortuneGame
public WheelOfFortuneGame(ulong userId, long bet, GamblingConfig config, ICurrencyService cs)
{
_rng = new NadekoRandom();
_rng = new();
_cs = cs;
_bet = bet;
_config = config;
@@ -36,7 +36,7 @@ public class WheelOfFortuneGame
if (amount > 0)
await _cs.AddAsync(_userId, "Wheel Of Fortune - won", amount, gamble: true).ConfigureAwait(false);
return new Result
return new()
{
Index = result,
Amount = amount,

View File

@@ -78,7 +78,7 @@ public sealed class Connect4Game : IDisposable
_options = options;
_cs = cs;
_rng = new NadekoRandom();
_rng = new();
for (var i = 0; i < NumberOfColumns * NumberOfRows; i++)
{
_gameState[i] = Field.Empty;
@@ -133,7 +133,7 @@ public sealed class Connect4Game : IDisposable
_players[1] = (userId, userName);
CurrentPhase = Phase.P1Move; //start the game
_playerTimeoutTimer = new Timer(async state =>
_playerTimeoutTimer = new(async state =>
{
await _locker.WaitAsync().ConfigureAwait(false);
try

View File

@@ -137,7 +137,7 @@ public partial class Gambling
Match match;
if ((match = fudgeRegex.Match(arg)).Length != 0 &&
int.TryParse(match.Groups["n1"].ToString(), out var n1) &&
n1 > 0 && n1 < 500)
n1 is > 0 and < 500)
{
var rng = new NadekoRandom();

View File

@@ -31,7 +31,7 @@ public partial class Gambling
if (num < 1 || num > 10)
throw new ArgumentOutOfRangeException(nameof(num));
var cards = guildId is null ? new Deck() : _allDecks.GetOrAdd(ctx.Guild, (s) => new Deck());
var cards = guildId is null ? new() : _allDecks.GetOrAdd(ctx.Guild, s => new());
var images = new List<Image<Rgba32>>();
var cardObjects = new List<Deck.Card>();
for (var i = 0; i < num; i++)
@@ -108,7 +108,7 @@ public partial class Gambling
//var channel = (ITextChannel)ctx.Channel;
_allDecks.AddOrUpdate(ctx.Guild,
(g) => new Deck(),
g => new(),
(g, c) =>
{
c.Restart();

View File

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

View File

@@ -34,7 +34,7 @@ public class CurrencyRaffleService : INService
if (!Games.TryGetValue(channelId, out var crg))
{
newGame = true;
crg = new CurrencyRaffleGame(mixed
crg = new(mixed
? CurrencyRaffleGame.Type.Mixed
: CurrencyRaffleGame.Type.Normal);
Games.Add(channelId, crg);

View File

@@ -24,7 +24,7 @@ public sealed class GamblingConfigService : ConfigServiceBase<GamblingConfig>
AddParsedProp("gen.min", gs => gs.Generation.MinAmount, int.TryParse, ConfigPrinters.ToString, val => val >= 1);
AddParsedProp("gen.max", gs => gs.Generation.MaxAmount, int.TryParse, ConfigPrinters.ToString, val => val >= 1);
AddParsedProp("gen.cd", gs => gs.Generation.GenCooldown, int.TryParse, ConfigPrinters.ToString, val => val > 0);
AddParsedProp("gen.chance", gs => gs.Generation.Chance, decimal.TryParse, ConfigPrinters.ToString, val => val >= 0 && val <= 1);
AddParsedProp("gen.chance", gs => gs.Generation.Chance, decimal.TryParse, ConfigPrinters.ToString, val => val is >= 0 and <= 1);
AddParsedProp("gen.has_pw", gs => gs.Generation.HasPassword, bool.TryParse, ConfigPrinters.ToString);
AddParsedProp("bf.multi", gs => gs.BetFlip.Multiplier, decimal.TryParse, ConfigPrinters.ToString, val => val >= 1);
AddParsedProp("waifu.min_price", gs => gs.Waifu.MinPrice, int.TryParse, ConfigPrinters.ToString, val => val >= 0);
@@ -35,7 +35,7 @@ public sealed class GamblingConfigService : ConfigServiceBase<GamblingConfig>
AddParsedProp("waifu.multi.all_gifts", gs => gs.Waifu.Multipliers.AllGiftPrices, decimal.TryParse, ConfigPrinters.ToString, val => val > 0);
AddParsedProp("waifu.multi.gift_effect", gs => gs.Waifu.Multipliers.GiftEffect, decimal.TryParse, ConfigPrinters.ToString, val => val >= 0);
AddParsedProp("waifu.multi.negative_gift_effect", gs => gs.Waifu.Multipliers.NegativeGiftEffect, decimal.TryParse, ConfigPrinters.ToString, val => val >= 0);
AddParsedProp("decay.percent", gs => gs.Decay.Percent, decimal.TryParse, ConfigPrinters.ToString, val => val >= 0 && val <= 1);
AddParsedProp("decay.percent", gs => gs.Decay.Percent, decimal.TryParse, ConfigPrinters.ToString, val => val is >= 0 and <= 1);
AddParsedProp("decay.maxdecay", gs => gs.Decay.MaxDecay, int.TryParse, ConfigPrinters.ToString, val => val >= 0);
AddParsedProp("decay.threshold", gs => gs.Decay.MinThreshold, int.TryParse, ConfigPrinters.ToString, val => val >= 0);

View File

@@ -39,7 +39,7 @@ public class GamblingService : INService
if (_bot.Client.ShardId == 0)
{
_decayTimer = new Timer(_ =>
_decayTimer = new(_ =>
{
var config = _gss.Data;
var maxDecay = config.Decay.MaxDecay;
@@ -85,7 +85,7 @@ WHERE CurrencyAmount > {config.Decay.MinThreshold} AND UserId!={_client.CurrentU
if (!takeRes)
{
return new SlotResponse
return new()
{
Error = GamblingError.NotEnough
};

View File

@@ -48,7 +48,7 @@ public class PlantPickService : INService
_fonts = fonts;
_cs = cs;
_cmdHandler = cmdHandler;
_rng = new NadekoRandom();
_rng = new();
_client = client;
_gss = gss;
@@ -62,7 +62,7 @@ public class PlantPickService : INService
.Where(x => guildIds.Contains(x.GuildId))
.ToList();
_generationChannels = new ConcurrentHashSet<ulong>(configs
_generationChannels = new(configs
.SelectMany(c => c.GenerateCurrencyChannelIds.Select(obj => obj.ChannelId)));
}
}
@@ -155,7 +155,7 @@ public class PlantPickService : INService
img.Mutate(x =>
{
// measure the size of the text to be drawing
var size = TextMeasurer.Measure(pass, new RendererOptions(font, new PointF(0, 0)));
var size = TextMeasurer.Measure(pass, new(font, new PointF(0, 0)));
// fill the background with black, add 5 pixels on each side to make it look better
x.FillPolygon(Color.ParseHex("00000080"),
@@ -168,7 +168,7 @@ public class PlantPickService : INService
x.DrawText(pass,
font,
SixLabors.ImageSharp.Color.White,
new PointF(0, 0));
new(0, 0));
});
// return image as a stream for easy sending
return (img.ToStream(format), format.FileExtensions.FirstOrDefault() ?? "png");
@@ -364,7 +364,7 @@ public class PlantPickService : INService
{
using (var uow = _db.GetDbContext())
{
uow.PlantedCurrency.Add(new PlantedCurrency
uow.PlantedCurrency.Add(new()
{
Amount = amount,
GuildId = gid,

View File

@@ -42,7 +42,7 @@ public class VoteRewardService : INService, IReadyExecutor
if (_client.ShardId != 0)
return;
_http = new HttpClient(new HttpClientHandler()
_http = new(new HttpClientHandler()
{
AllowAutoRedirect = false,
ServerCertificateCustomValidationCallback = delegate { return true; }

View File

@@ -175,14 +175,14 @@ public class WaifuService : INService
}
else
{
uow.WaifuInfo.Add(w = new WaifuInfo()
uow.WaifuInfo.Add(w = new()
{
Waifu = waifu,
Claimer = claimer,
Affinity = null,
Price = amount
});
uow.WaifuUpdates.Add(new WaifuUpdate()
uow.WaifuUpdates.Add(new()
{
User = waifu,
Old = null,
@@ -205,7 +205,7 @@ public class WaifuService : INService
w.Price = amount + (amount / 4);
result = WaifuClaimResult.Success;
uow.WaifuUpdates.Add(new WaifuUpdate()
uow.WaifuUpdates.Add(new()
{
User = w.Waifu,
Old = oldClaimer,
@@ -227,7 +227,7 @@ public class WaifuService : INService
w.Price = amount;
result = WaifuClaimResult.Success;
uow.WaifuUpdates.Add(new WaifuUpdate()
uow.WaifuUpdates.Add(new()
{
User = w.Waifu,
Old = oldClaimer,
@@ -264,7 +264,7 @@ public class WaifuService : INService
else if (w is null)
{
var thisUser = uow.GetOrCreateUser(user);
uow.WaifuInfo.Add(new WaifuInfo()
uow.WaifuInfo.Add(new()
{
Affinity = newAff,
Waifu = thisUser,
@@ -273,7 +273,7 @@ public class WaifuService : INService
});
success = true;
uow.WaifuUpdates.Add(new WaifuUpdate()
uow.WaifuUpdates.Add(new()
{
User = thisUser,
Old = null,
@@ -288,7 +288,7 @@ public class WaifuService : INService
w.Affinity = newAff;
success = true;
uow.WaifuUpdates.Add(new WaifuUpdate()
uow.WaifuUpdates.Add(new()
{
User = w.Waifu,
Old = oldAff,
@@ -353,7 +353,7 @@ public class WaifuService : INService
var oldClaimer = w.Claimer;
w.Claimer = null;
uow.WaifuUpdates.Add(new WaifuUpdate()
uow.WaifuUpdates.Add(new()
{
User = w.Waifu,
Old = oldClaimer,
@@ -382,7 +382,7 @@ public class WaifuService : INService
.Include(x => x.Claimer));
if (w is null)
{
uow.WaifuInfo.Add(w = new WaifuInfo()
uow.WaifuInfo.Add(w = new()
{
Affinity = null,
Claimer = null,
@@ -393,7 +393,7 @@ public class WaifuService : INService
if (!itemObj.Negative)
{
w.Items.Add(new WaifuItem()
w.Items.Add(new()
{
Name = itemObj.Name.ToLowerInvariant(),
ItemEmoji = itemObj.ItemEmoji,
@@ -428,17 +428,17 @@ public class WaifuService : INService
var wi = uow.GetWaifuInfo(targetId);
if (wi is null)
{
wi = new WaifuInfoStats
wi = new()
{
AffinityCount = 0,
AffinityName = null,
ClaimCount = 0,
ClaimerName = null,
Claims = new List<string>(),
Fans = new List<string>(),
Claims = new(),
Fans = new(),
DivorceCount = 0,
FullName = null,
Items = new List<WaifuItem>(),
Items = new(),
Price = 1
};
}

View File

@@ -49,7 +49,7 @@ public partial class Gambling
set => set.Include(x => x.ShopEntries)
.ThenInclude(x => x.Items)).ShopEntries
.ToIndexed();
return ctx.SendPaginatedConfirmAsync(page, (curPage) =>
return ctx.SendPaginatedConfirmAsync(page, curPage =>
{
var theseEntries = entries.Skip(curPage * 9).Take(9).ToArray();
@@ -261,7 +261,7 @@ public partial class Gambling
Price = price,
Type = ShopEntryType.List,
AuthorId = ctx.User.Id,
Items = new HashSet<ShopEntryItem>(),
Items = new(),
};
using (var uow = _db.GetDbContext())
{

View File

@@ -54,13 +54,13 @@ public partial class Gambling
static readonly List<Func<int[], int>> _winningCombos = new List<Func<int[], int>>()
{
//three flowers
(arr) => arr.All(a=>a==MaxValue) ? 30 : 0,
arr => arr.All(a=>a==MaxValue) ? 30 : 0,
//three of the same
(arr) => !arr.Any(a => a != arr[0]) ? 10 : 0,
arr => !arr.Any(a => a != arr[0]) ? 10 : 0,
//two flowers
(arr) => arr.Count(a => a == MaxValue) == 2 ? 4 : 0,
arr => arr.Count(a => a == MaxValue) == 2 ? 4 : 0,
//one flower
(arr) => arr.Any(a => a == MaxValue) ? 1 : 0,
arr => arr.Any(a => a == MaxValue) ? 1 : 0,
};
public static SlotResult Pull()
@@ -78,7 +78,7 @@ public partial class Gambling
break;
}
return new SlotResult(numbers, multi);
return new(numbers, multi);
}
public struct SlotResult
@@ -186,40 +186,40 @@ public partial class Gambling
Color fontColor = _config.Slots.CurrencyFontColor;
bgImage.Mutate(x => x.DrawText(new TextGraphicsOptions
bgImage.Mutate(x => x.DrawText(new()
{
TextOptions = new TextOptions()
TextOptions = new()
{
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
WrapTextWidth = 140,
}
}, result.Won.ToString(), _fonts.DottyFont.CreateFont(65), fontColor,
new PointF(227, 92)));
new(227, 92)));
var bottomFont = _fonts.DottyFont.CreateFont(50);
bgImage.Mutate(x => x.DrawText(new TextGraphicsOptions
bgImage.Mutate(x => x.DrawText(new()
{
TextOptions = new TextOptions()
TextOptions = new()
{
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
WrapTextWidth = 135,
}
}, amount.ToString(), bottomFont, fontColor,
new PointF(129, 472)));
new(129, 472)));
bgImage.Mutate(x => x.DrawText(new TextGraphicsOptions
bgImage.Mutate(x => x.DrawText(new()
{
TextOptions = new TextOptions()
TextOptions = new()
{
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
WrapTextWidth = 135,
}
}, ownedAmount.ToString(), bottomFont, fontColor,
new PointF(325, 472)));
new(325, 472)));
//sw.PrintLap("drew red text");
for (var i = 0; i < 3; i++)

View File

@@ -308,7 +308,7 @@ public partial class Gambling
return;
var waifuItems = _service.GetWaifuItems();
await ctx.SendPaginatedConfirmAsync(page, (cur) =>
await ctx.SendPaginatedConfirmAsync(page, cur =>
{
var embed = _eb.Create()
.WithTitle(GetText(strs.waifu_gift_shop))