namespace VpSharp.Commands.Attributes.ExecutionChecks;
#pragma warning disable CA1019 // Define accessors for attribute arguments
///
/// Specifies that this command can only be run by bots.
///
public sealed class RequireUserIdAttribute : PreExecutionCheckAttribute
{
///
/// Initializes a new instance of the class.
///
/// An enumerable collection of allowed user IDs.
/// is .
public RequireUserIdAttribute(IEnumerable userIds)
{
if (userIds is null)
{
throw new ArgumentNullException(nameof(userIds));
}
UserIds = userIds.ToArray();
}
///
/// Initializes a new instance of the class.
///
/// An array of allowed user IDs.
/// is .
[CLSCompliant(false)]
public RequireUserIdAttribute(params int[] userIds)
{
if (userIds is null)
{
throw new ArgumentNullException(nameof(userIds));
}
UserIds = userIds[..];
}
///
/// Gets a read-only view of the user IDs allowed to run this command.
///
/// A of representing the allowed user IDs.
public IReadOnlyList UserIds { get; }
///
protected internal override Task PerformAsync(CommandContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
return Task.FromResult(UserIds.Contains(context.Avatar.UserId));
}
}