-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add previously missing InfractionOptions struct
- Loading branch information
1 parent
ba2d8dc
commit ba9d6ff
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using System; | ||
|
||
namespace Hammer.Data.Infractions; | ||
|
||
/// <summary> | ||
/// Specifies options to provide to <see cref="Hammer.Services.InfractionService.CreateInfractionAsync" />. | ||
/// </summary> | ||
internal readonly struct InfractionOptions | ||
{ | ||
private readonly DateTimeOffset? _expirationTime; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="InfractionOptions" /> structure. | ||
/// </summary> | ||
public InfractionOptions() | ||
{ | ||
_expirationTime = null; | ||
NotifyUser = true; | ||
Reason = null; | ||
} | ||
|
||
/// <summary> | ||
/// Gets or initializes the duration of the infraction. | ||
/// </summary> | ||
/// <value>The duration of the ban, or <see langword="null" /> to indicate the ban is permanent.</value> | ||
/// <remarks>It's only necessary to initialize this value, or <see cref="ExpirationTime" />, not both.</remarks> | ||
/// <seealso cref="ExpirationTime" /> | ||
public TimeSpan? Duration | ||
{ | ||
get => _expirationTime.HasValue ? _expirationTime - DateTimeOffset.UtcNow : null; | ||
init => _expirationTime = value.HasValue ? DateTimeOffset.UtcNow + value : null; | ||
} | ||
|
||
/// <summary> | ||
/// Gets or initializes the duration of the infraction. | ||
/// </summary> | ||
/// <value>The duration of the ban, or <see langword="null" /> to indicate the ban is permanent.</value> | ||
/// <remarks>It's only necessary to initialize this value, or <see cref="Duration" />, not both.</remarks> | ||
/// <seealso cref="Duration" /> | ||
public DateTimeOffset? ExpirationTime | ||
{ | ||
get => _expirationTime; | ||
init => _expirationTime = value; | ||
} | ||
|
||
/// <summary> | ||
/// Gets or initializes a value indicating whether the user should be notified of the infraction. | ||
/// </summary> | ||
/// <value><see langword="true" /> to notify the user; otherwise, <see langword="false" />.</value> | ||
public bool NotifyUser { get; init; } | ||
|
||
/// <summary> | ||
/// Gets or initializes the reason for the infraction. | ||
/// </summary> | ||
/// <value>The reason.</value> | ||
public string? Reason { get; init; } | ||
} |