-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCooldown.cs
More file actions
63 lines (56 loc) · 2.17 KB
/
Cooldown.cs
File metadata and controls
63 lines (56 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using Ultz.Extensions.Commands.Built;
namespace Ultz.Extensions.Commands.Cooldown
{
/// <summary>
/// Represents a <see cref="Command" /> cooldown.
/// </summary>
public sealed class Cooldown
{
/// <summary>
/// Initialises a new <see cref="Cooldown" /> with the specified properties.
/// </summary>
/// <param name="amount"> The amount of uses per given window. </param>
/// <param name="per"> The bucket time window. </param>
/// <param name="bucketType"> The <see langword="enum" /> bucket type. </param>
/// <exception cref="ArgumentOutOfRangeException">
/// Amount and per must be positive values.
/// </exception>
/// <exception cref="ArgumentNullException">
/// Bucket type must not be <see langword="null" />.
/// </exception>
/// <exception cref="ArgumentException">
/// Bucket type must be an <see langword="enum" />.
/// </exception>
public Cooldown(int amount, TimeSpan per, Enum bucketType)
{
if (amount <= 0)
{
throw new ArgumentOutOfRangeException(nameof(amount), "Amount must be a positive integer.");
}
if (per <= TimeSpan.Zero)
{
throw new ArgumentOutOfRangeException(nameof(per), "Per must be a positive time span.");
}
if (bucketType == null)
{
throw new ArgumentNullException(nameof(bucketType), "Bucket type must not be null.");
}
Amount = amount;
Per = per;
BucketType = bucketType;
}
/// <summary>
/// Gets the amount of times the <see cref="Command" /> can be used in the given time window.
/// </summary>
public int Amount { get; }
/// <summary>
/// Gets the time window of this cooldown.
/// </summary>
public TimeSpan Per { get; }
/// <summary>
/// Gets the <see langword="enum" /> bucket type to use with the <see cref="CooldownBucketKeyGeneratorDelegate" />.
/// </summary>
public Enum BucketType { get; }
}
}