Skip to content

Commit

Permalink
Add previously missing InfractionOptions struct
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverbooth committed Mar 19, 2022
1 parent ba2d8dc commit ba9d6ff
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions Hammer/Data/Infractions/InfractionOptions.cs
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; }
}

0 comments on commit ba9d6ff

Please sign in to comment.