dev: Added argumentoutofrange static methods, no functional change

This commit is contained in:
Kwoth
2024-05-13 14:50:55 +00:00
parent 7b2ce072ee
commit 52438f45e1
24 changed files with 69 additions and 116 deletions

View File

@@ -22,8 +22,7 @@ public static class WarningExtensions
string mod, string mod,
int index) int index)
{ {
if (index < 0) ArgumentOutOfRangeException.ThrowIfNegative(index);
throw new ArgumentOutOfRangeException(nameof(index));
var warn = warnings.AsQueryable() var warn = warnings.AsQueryable()
.Where(x => x.GuildId == guildId && x.UserId == userId) .Where(x => x.GuildId == guildId && x.UserId == userId)

View File

@@ -69,8 +69,7 @@ public sealed class PlayingRotateService : INService, IReadyExecutor
public async Task<string> RemovePlayingAsync(int index) public async Task<string> RemovePlayingAsync(int index)
{ {
if (index < 0) ArgumentOutOfRangeException.ThrowIfNegative(index);
throw new ArgumentOutOfRangeException(nameof(index));
await using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();
var toRemove = await uow.Set<RotatingPlayingStatus>().AsQueryable().AsNoTracking().Skip(index).FirstOrDefaultAsync(); var toRemove = await uow.Set<RotatingPlayingStatus>().AsQueryable().AsNoTracking().Skip(index).FirstOrDefaultAsync();

View File

@@ -22,8 +22,7 @@ public class PruneService : INService
ArgumentNullException.ThrowIfNull(channel, nameof(channel)); ArgumentNullException.ThrowIfNull(channel, nameof(channel));
var originalAmount = amount; var originalAmount = amount;
if (amount <= 0) ArgumentOutOfRangeException.ThrowIfNegativeOrZero(amount);
throw new ArgumentOutOfRangeException(nameof(amount));
using var cancelSource = new CancellationTokenSource(); using var cancelSource = new CancellationTokenSource();
if (!_pruningGuilds.TryAdd(channel.GuildId, cancelSource)) if (!_pruningGuilds.TryAdd(channel.GuildId, cancelSource))

View File

@@ -250,11 +250,9 @@ public sealed class ReactionRolesService : IReadyExecutor, INService, IReactionR
int group = 0, int group = 0,
int levelReq = 0) int levelReq = 0)
{ {
if (group < 0) ArgumentOutOfRangeException.ThrowIfNegative(group);
throw new ArgumentOutOfRangeException(nameof(group));
if (levelReq < 0) ArgumentOutOfRangeException.ThrowIfNegative(levelReq);
throw new ArgumentOutOfRangeException(nameof(group));
await using var ctx = _db.GetDbContext(); await using var ctx = _db.GetDbContext();

View File

@@ -64,8 +64,7 @@ public class UserPunishService : INService, IReadyExecutor
long weight, long weight,
string reason) string reason)
{ {
if (weight <= 0) ArgumentOutOfRangeException.ThrowIfNegativeOrZero(weight);
throw new ArgumentOutOfRangeException(nameof(weight));
var modName = mod.ToString(); var modName = mod.ToString();

View File

@@ -61,8 +61,7 @@ public sealed class AnimalRace : IDisposable
public async Task<AnimalRacingUser> JoinRace(ulong userId, string userName, long bet = 0) public async Task<AnimalRacingUser> JoinRace(ulong userId, string userName, long bet = 0)
{ {
if (bet < 0) ArgumentOutOfRangeException.ThrowIfNegative(bet);
throw new ArgumentOutOfRangeException(nameof(bet));
var user = new AnimalRacingUser(userName, userId, bet); var user = new AnimalRacingUser(userName, userId, bet);

View File

@@ -17,8 +17,7 @@ public sealed class BankService : IBankService, INService
public async Task<bool> AwardAsync(ulong userId, long amount) public async Task<bool> AwardAsync(ulong userId, long amount)
{ {
if (amount <= 0) ArgumentOutOfRangeException.ThrowIfNegativeOrZero(amount);
throw new ArgumentOutOfRangeException(nameof(amount));
await using var ctx = _db.GetDbContext(); await using var ctx = _db.GetDbContext();
await ctx.GetTable<BankUser>() await ctx.GetTable<BankUser>()
@@ -41,8 +40,7 @@ public sealed class BankService : IBankService, INService
public async Task<bool> TakeAsync(ulong userId, long amount) public async Task<bool> TakeAsync(ulong userId, long amount)
{ {
if (amount <= 0) ArgumentOutOfRangeException.ThrowIfNegativeOrZero(amount);
throw new ArgumentOutOfRangeException(nameof(amount));
await using var ctx = _db.GetDbContext(); await using var ctx = _db.GetDbContext();
var rows = await ctx.Set<BankUser>() var rows = await ctx.Set<BankUser>()
@@ -58,8 +56,7 @@ public sealed class BankService : IBankService, INService
public async Task<bool> DepositAsync(ulong userId, long amount) public async Task<bool> DepositAsync(ulong userId, long amount)
{ {
if (amount <= 0) ArgumentOutOfRangeException.ThrowIfNegativeOrZero(amount);
throw new ArgumentOutOfRangeException(nameof(amount));
if (!await _cur.RemoveAsync(userId, amount, new("bank", "deposit"))) if (!await _cur.RemoveAsync(userId, amount, new("bank", "deposit")))
return false; return false;
@@ -86,8 +83,7 @@ public sealed class BankService : IBankService, INService
public async Task<bool> WithdrawAsync(ulong userId, long amount) public async Task<bool> WithdrawAsync(ulong userId, long amount)
{ {
if (amount <= 0) ArgumentOutOfRangeException.ThrowIfNegativeOrZero(amount);
throw new ArgumentOutOfRangeException(nameof(amount));
await using var ctx = _db.GetDbContext(); await using var ctx = _db.GetDbContext();
var rows = await ctx.Set<BankUser>() var rows = await ctx.Set<BankUser>()

View File

@@ -49,8 +49,7 @@ public class User : Player
public User(IUser user, long bet) public User(IUser user, long bet)
{ {
if (bet <= 0) ArgumentOutOfRangeException.ThrowIfNegativeOrZero(bet);
throw new ArgumentOutOfRangeException(nameof(bet));
Bet = bet; Bet = bet;
DiscordUser = user; DiscordUser = user;

View File

@@ -20,10 +20,8 @@ public class ShopService : IShopService, INService
public async Task<bool> ChangeEntryPriceAsync(ulong guildId, int index, int newPrice) public async Task<bool> ChangeEntryPriceAsync(ulong guildId, int index, int newPrice)
{ {
if (index < 0) ArgumentOutOfRangeException.ThrowIfNegative(index);
throw new ArgumentOutOfRangeException(nameof(index)); ArgumentOutOfRangeException.ThrowIfNegativeOrZero(newPrice);
if (newPrice <= 0)
throw new ArgumentOutOfRangeException(nameof(newPrice));
await using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();
var entries = GetEntriesInternal(uow, guildId); var entries = GetEntriesInternal(uow, guildId);
@@ -38,8 +36,8 @@ public class ShopService : IShopService, INService
public async Task<bool> ChangeEntryNameAsync(ulong guildId, int index, string newName) public async Task<bool> ChangeEntryNameAsync(ulong guildId, int index, string newName)
{ {
if (index < 0) ArgumentOutOfRangeException.ThrowIfNegative(index);
throw new ArgumentOutOfRangeException(nameof(index));
if (string.IsNullOrWhiteSpace(newName)) if (string.IsNullOrWhiteSpace(newName))
throw new ArgumentNullException(nameof(newName)); throw new ArgumentNullException(nameof(newName));
@@ -56,10 +54,8 @@ public class ShopService : IShopService, INService
public async Task<bool> SwapEntriesAsync(ulong guildId, int index1, int index2) public async Task<bool> SwapEntriesAsync(ulong guildId, int index1, int index2)
{ {
if (index1 < 0) ArgumentOutOfRangeException.ThrowIfNegative(index1);
throw new ArgumentOutOfRangeException(nameof(index1)); ArgumentOutOfRangeException.ThrowIfNegative(index2);
if (index2 < 0)
throw new ArgumentOutOfRangeException(nameof(index2));
await using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();
var entries = GetEntriesInternal(uow, guildId); var entries = GetEntriesInternal(uow, guildId);
@@ -76,10 +72,8 @@ public class ShopService : IShopService, INService
public async Task<bool> MoveEntryAsync(ulong guildId, int fromIndex, int toIndex) public async Task<bool> MoveEntryAsync(ulong guildId, int fromIndex, int toIndex)
{ {
if (fromIndex < 0) ArgumentOutOfRangeException.ThrowIfNegative(fromIndex);
throw new ArgumentOutOfRangeException(nameof(fromIndex)); ArgumentOutOfRangeException.ThrowIfNegative(toIndex);
if (toIndex < 0)
throw new ArgumentOutOfRangeException(nameof(toIndex));
await using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();
var entries = GetEntriesInternal(uow, guildId); var entries = GetEntriesInternal(uow, guildId);

View File

@@ -27,8 +27,8 @@ public static class WaifuExtensions
public static IEnumerable<WaifuLbResult> GetTop(this DbSet<WaifuInfo> waifus, int count, int skip = 0) public static IEnumerable<WaifuLbResult> GetTop(this DbSet<WaifuInfo> waifus, int count, int skip = 0)
{ {
if (count < 0) ArgumentOutOfRangeException.ThrowIfNegative(count);
throw new ArgumentOutOfRangeException(nameof(count));
if (count == 0) if (count == 0)
return new List<WaifuLbResult>(); return new List<WaifuLbResult>();

View File

@@ -14,5 +14,5 @@ public interface IGamblingService
Task<OneOf<SlotResult, GamblingError>> SlotAsync(ulong userId, long amount); Task<OneOf<SlotResult, GamblingError>> SlotAsync(ulong userId, long amount);
Task<FlipResult[]> FlipAsync(int count); Task<FlipResult[]> FlipAsync(int count);
Task<OneOf<RpsResult, GamblingError>> RpsAsync(ulong userId, long amount, byte pick); Task<OneOf<RpsResult, GamblingError>> RpsAsync(ulong userId, long amount, byte pick);
Task<OneOf<BetdrawResult, GamblingError>> BetDrawAsync(ulong userId, long amount, byte? guessValue, byte? guessColor); Task<OneOf<BetdrawResult, GamblingError>> BetDrawAsync(ulong userId, long amount, byte? maybeGuessValue, byte? maybeGuessColor);
} }

View File

@@ -20,8 +20,7 @@ public sealed class NewGamblingService : IGamblingService, INService
public async Task<OneOf<LuLaResult, GamblingError>> LulaAsync(ulong userId, long amount) public async Task<OneOf<LuLaResult, GamblingError>> LulaAsync(ulong userId, long amount)
{ {
if (amount < 0) ArgumentOutOfRangeException.ThrowIfNegative(amount);
throw new ArgumentOutOfRangeException(nameof(amount));
if (amount > 0) if (amount > 0)
{ {
@@ -47,8 +46,7 @@ public sealed class NewGamblingService : IGamblingService, INService
public async Task<OneOf<BetrollResult, GamblingError>> BetRollAsync(ulong userId, long amount) public async Task<OneOf<BetrollResult, GamblingError>> BetRollAsync(ulong userId, long amount)
{ {
if (amount < 0) ArgumentOutOfRangeException.ThrowIfNegative(amount);
throw new ArgumentOutOfRangeException(nameof(amount));
if (amount > 0) if (amount > 0)
{ {
@@ -77,11 +75,9 @@ public sealed class NewGamblingService : IGamblingService, INService
public async Task<OneOf<BetflipResult, GamblingError>> BetFlipAsync(ulong userId, long amount, byte guess) public async Task<OneOf<BetflipResult, GamblingError>> BetFlipAsync(ulong userId, long amount, byte guess)
{ {
if (amount < 0) ArgumentOutOfRangeException.ThrowIfNegative(amount);
throw new ArgumentOutOfRangeException(nameof(amount));
if (guess > 1) ArgumentOutOfRangeException.ThrowIfGreaterThan(guess, 1);
throw new ArgumentOutOfRangeException(nameof(guess));
if (amount > 0) if (amount > 0)
{ {
@@ -105,19 +101,18 @@ public sealed class NewGamblingService : IGamblingService, INService
return result; return result;
} }
public async Task<OneOf<BetdrawResult, GamblingError>> BetDrawAsync(ulong userId, long amount, byte? guessValue, byte? guessColor) public async Task<OneOf<BetdrawResult, GamblingError>> BetDrawAsync(ulong userId, long amount, byte? maybeGuessValue, byte? maybeGuessColor)
{ {
if (amount < 0) ArgumentOutOfRangeException.ThrowIfNegative(amount);
throw new ArgumentOutOfRangeException(nameof(amount));
if (guessColor is null && guessValue is null) if (maybeGuessColor is null && maybeGuessValue is null)
throw new ArgumentNullException(); throw new ArgumentNullException();
if (guessColor > 1) if (maybeGuessColor > 1)
throw new ArgumentOutOfRangeException(nameof(guessColor)); throw new ArgumentOutOfRangeException(nameof(maybeGuessColor));
if (guessValue > 1) if (maybeGuessValue > 1)
throw new ArgumentOutOfRangeException(nameof(guessValue)); throw new ArgumentOutOfRangeException(nameof(maybeGuessValue));
if (amount > 0) if (amount > 0)
{ {
@@ -130,7 +125,7 @@ public sealed class NewGamblingService : IGamblingService, INService
} }
var game = new BetdrawGame(); var game = new BetdrawGame();
var result = game.Draw((BetdrawValueGuess?)guessValue, (BetdrawColorGuess?)guessColor, amount); var result = game.Draw((BetdrawValueGuess?)maybeGuessValue, (BetdrawColorGuess?)maybeGuessColor, amount);
var won = (long)result.Won; var won = (long)result.Won;
if (won > 0) if (won > 0)
@@ -143,8 +138,7 @@ public sealed class NewGamblingService : IGamblingService, INService
public async Task<OneOf<SlotResult, GamblingError>> SlotAsync(ulong userId, long amount) public async Task<OneOf<SlotResult, GamblingError>> SlotAsync(ulong userId, long amount)
{ {
if (amount < 0) ArgumentOutOfRangeException.ThrowIfNegative(amount);
throw new ArgumentOutOfRangeException(nameof(amount));
if (amount > 0) if (amount > 0)
{ {
@@ -170,8 +164,7 @@ public sealed class NewGamblingService : IGamblingService, INService
public Task<FlipResult[]> FlipAsync(int count) public Task<FlipResult[]> FlipAsync(int count)
{ {
if (count < 1) ArgumentOutOfRangeException.ThrowIfLessThan(count, 1);
throw new ArgumentOutOfRangeException(nameof(count));
var game = new BetflipGame(0); var game = new BetflipGame(0);
@@ -242,11 +235,8 @@ public sealed class NewGamblingService : IGamblingService, INService
public async Task<OneOf<RpsResult, GamblingError>> RpsAsync(ulong userId, long amount, byte pick) public async Task<OneOf<RpsResult, GamblingError>> RpsAsync(ulong userId, long amount, byte pick)
{ {
if (amount < 0) ArgumentOutOfRangeException.ThrowIfNegative(amount);
throw new ArgumentOutOfRangeException(nameof(amount)); ArgumentOutOfRangeException.ThrowIfGreaterThan(pick, 2);
if (pick > 2)
throw new ArgumentOutOfRangeException(nameof(pick));
if (amount > 0) if (amount > 0)
{ {

View File

@@ -201,12 +201,9 @@ public sealed partial class MusicQueue : IMusicQueue
public IQueuedTrackInfo? MoveTrack(int from, int to) public IQueuedTrackInfo? MoveTrack(int from, int to)
{ {
if (from < 0) ArgumentOutOfRangeException.ThrowIfNegative(from);
throw new ArgumentOutOfRangeException(nameof(from)); ArgumentOutOfRangeException.ThrowIfNegative(to);
if (to < 0) ArgumentOutOfRangeException.ThrowIfEqual(to, from);
throw new ArgumentOutOfRangeException(nameof(to));
if (to == from)
throw new ArgumentException($"{nameof(from)} and {nameof(to)} must be different");
lock (_locker) lock (_locker)
{ {

View File

@@ -8,8 +8,7 @@ public static class MusicPlaylistExtensions
{ {
public static List<MusicPlaylist> GetPlaylistsOnPage(this DbSet<MusicPlaylist> playlists, int num) public static List<MusicPlaylist> GetPlaylistsOnPage(this DbSet<MusicPlaylist> playlists, int num)
{ {
if (num < 1) ArgumentOutOfRangeException.ThrowIfLessThan(num, 1);
throw new ArgumentOutOfRangeException(nameof(num));
return playlists.AsQueryable().Skip((num - 1) * 20).Take(20).Include(pl => pl.Songs).ToList(); return playlists.AsQueryable().Skip((num - 1) * 20).Take(20).Include(pl => pl.Songs).ToList();
} }

View File

@@ -16,8 +16,7 @@ public partial class Permissions
private async Task ListBlacklistInternal(string title, BlacklistType type, int page = 0) private async Task ListBlacklistInternal(string title, BlacklistType type, int page = 0)
{ {
if (page < 0) ArgumentOutOfRangeException.ThrowIfNegative(page);
throw new ArgumentOutOfRangeException(nameof(page));
var list = _service.GetBlacklist(); var list = _service.GetBlacklist();
var allItems = await list.Where(x => x.Type == type) var allItems = await list.Where(x => x.Type == type)

View File

@@ -112,8 +112,7 @@ public sealed class CmdCdService : IExecPreCommand, IReadyExecutor, INService
public void AddCooldown(ulong guildId, string name, int secs) public void AddCooldown(ulong guildId, string name, int secs)
{ {
if (secs <= 0) ArgumentOutOfRangeException.ThrowIfNegativeOrZero(secs);
throw new ArgumentOutOfRangeException(nameof(secs));
var sett = _settings.GetOrAdd(guildId, static _ => new()); var sett = _settings.GetOrAdd(guildId, static _ => new());
sett[name] = secs; sett[name] = secs;

View File

@@ -2,7 +2,7 @@
public class PlainGoogleScrapeSearchResult : ISearchResult public class PlainGoogleScrapeSearchResult : ISearchResult
{ {
public string? Answer { get; init; } = null!; public required string? Answer { get; init; }
public IReadOnlyCollection<ISearchResultEntry> Entries { get; init; } = null!; public required IReadOnlyCollection<ISearchResultEntry> Entries { get; init; }
public ISearchResultInformation Info { get; init; } = null!; public required ISearchResultInformation Info { get; init; }
} }

View File

@@ -363,8 +363,7 @@ public sealed class RepeaterService : IReadyExecutor, INService
public async Task<RunningRepeater?> RemoveByIndexAsync(ulong guildId, int index) public async Task<RunningRepeater?> RemoveByIndexAsync(ulong guildId, int index)
{ {
if (index > MAX_REPEATERS * 2) ArgumentOutOfRangeException.ThrowIfGreaterThan(index, MAX_REPEATERS * 2);
throw new ArgumentOutOfRangeException(nameof(index));
await using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();
var toRemove = await uow.Set<Repeater>() var toRemove = await uow.Set<Repeater>()

View File

@@ -332,8 +332,7 @@ public class ClubService : INService, IClubService
public List<ClubInfo> GetClubLeaderboardPage(int page) public List<ClubInfo> GetClubLeaderboardPage(int page)
{ {
if (page < 0) ArgumentOutOfRangeException.ThrowIfNegative(page);
throw new ArgumentOutOfRangeException(nameof(page));
using var uow = _db.GetDbContext(); using var uow = _db.GetDbContext();
return uow.Set<ClubInfo>().GetClubLeaderboardPage(page); return uow.Set<ClubInfo>().GetClubLeaderboardPage(page);

View File

@@ -43,8 +43,7 @@ public sealed partial class GoogleApiService : IGoogleApiService, INService
if (string.IsNullOrWhiteSpace(keywords)) if (string.IsNullOrWhiteSpace(keywords))
throw new ArgumentNullException(nameof(keywords)); throw new ArgumentNullException(nameof(keywords));
if (count <= 0) ArgumentOutOfRangeException.ThrowIfNegativeOrZero(count);
throw new ArgumentOutOfRangeException(nameof(count));
var match = _plRegex.Match(keywords); var match = _plRegex.Match(keywords);
if (match.Length > 1) if (match.Length > 1)
@@ -62,8 +61,7 @@ public sealed partial class GoogleApiService : IGoogleApiService, INService
if (string.IsNullOrWhiteSpace(id)) if (string.IsNullOrWhiteSpace(id))
throw new ArgumentNullException(nameof(id)); throw new ArgumentNullException(nameof(id));
if (count <= 0) ArgumentOutOfRangeException.ThrowIfNegativeOrZero(count);
throw new ArgumentOutOfRangeException(nameof(count));
var query = _yt.Search.List("snippet"); var query = _yt.Search.List("snippet");
query.MaxResults = count; query.MaxResults = count;
@@ -82,8 +80,7 @@ public sealed partial class GoogleApiService : IGoogleApiService, INService
if (string.IsNullOrWhiteSpace(keywords)) if (string.IsNullOrWhiteSpace(keywords))
throw new ArgumentNullException(nameof(keywords)); throw new ArgumentNullException(nameof(keywords));
if (count <= 0) ArgumentOutOfRangeException.ThrowIfNegativeOrZero(count);
throw new ArgumentOutOfRangeException(nameof(count));
var query = _yt.Search.List("snippet"); var query = _yt.Search.List("snippet");
query.MaxResults = count; query.MaxResults = count;
@@ -100,8 +97,7 @@ public sealed partial class GoogleApiService : IGoogleApiService, INService
if (string.IsNullOrWhiteSpace(keywords)) if (string.IsNullOrWhiteSpace(keywords))
throw new ArgumentNullException(nameof(keywords)); throw new ArgumentNullException(nameof(keywords));
if (count <= 0) ArgumentOutOfRangeException.ThrowIfNegativeOrZero(count);
throw new ArgumentOutOfRangeException(nameof(count));
var query = _yt.Search.List("snippet"); var query = _yt.Search.List("snippet");
query.MaxResults = count; query.MaxResults = count;
@@ -150,8 +146,7 @@ public sealed partial class GoogleApiService : IGoogleApiService, INService
if (string.IsNullOrWhiteSpace(playlistId)) if (string.IsNullOrWhiteSpace(playlistId))
throw new ArgumentNullException(nameof(playlistId)); throw new ArgumentNullException(nameof(playlistId));
if (count <= 0) ArgumentOutOfRangeException.ThrowIfNegativeOrZero(count);
throw new ArgumentOutOfRangeException(nameof(count));
string nextPageToken = null; string nextPageToken = null;

View File

@@ -46,12 +46,8 @@ public sealed class ConcurrentHashSet<T> : IReadOnlyCollection<T>, ICollection<T
public void CopyTo(T[] array, int arrayIndex) public void CopyTo(T[] array, int arrayIndex)
{ {
ArgumentNullException.ThrowIfNull(array); ArgumentNullException.ThrowIfNull(array);
ArgumentOutOfRangeException.ThrowIfNegative(arrayIndex);
if (arrayIndex < 0) ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(arrayIndex, array.Length);
throw new ArgumentOutOfRangeException(nameof(arrayIndex));
if (arrayIndex >= array.Length)
throw new ArgumentOutOfRangeException(nameof(arrayIndex));
CopyToInternal(array, arrayIndex); CopyToInternal(array, arrayIndex);
} }

View File

@@ -38,8 +38,8 @@ public sealed class NadekoRandom : Random
public long NextLong(long minValue, long maxValue) public long NextLong(long minValue, long maxValue)
{ {
if (minValue > maxValue) ArgumentOutOfRangeException.ThrowIfGreaterThan(minValue, maxValue);
throw new ArgumentOutOfRangeException(nameof(maxValue));
if (minValue == maxValue) if (minValue == maxValue)
return minValue; return minValue;
var bytes = new byte[sizeof(long)]; var bytes = new byte[sizeof(long)];

View File

@@ -9,8 +9,7 @@ public sealed class QueueRunner
public QueueRunner(int delayMs = 0, int maxCapacity = -1) public QueueRunner(int delayMs = 0, int maxCapacity = -1)
{ {
if (delayMs < 0) ArgumentOutOfRangeException.ThrowIfNegative(delayMs);
throw new ArgumentOutOfRangeException(nameof(delayMs));
_delayMs = delayMs; _delayMs = delayMs;
_channel = maxCapacity switch _channel = maxCapacity switch

View File

@@ -9,8 +9,7 @@ public sealed class RatelimitAttribute : PreconditionAttribute
public RatelimitAttribute(int seconds) public RatelimitAttribute(int seconds)
{ {
if (seconds <= 0) ArgumentOutOfRangeException.ThrowIfNegativeOrZero(seconds);
throw new ArgumentOutOfRangeException(nameof(seconds));
Seconds = seconds; Seconds = seconds;
} }