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)
{
ArgumentNullException.ThrowIfNull(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)
{
ArgumentNullException.ThrowIfNull(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)
{
ArgumentNullException.ThrowIfNull(context);
return Task.FromResult(UserIds.Contains(context.Avatar.User.Id));
}
}