using VpSharp.Entities;
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 RequireUserNameAttribute : PreExecutionCheckAttribute
{
///
/// Initializes a new instance of the class.
///
/// An enumerable collection of allowed user names.
/// is .
public RequireUserNameAttribute(IEnumerable names)
{
if (names is null)
{
throw new ArgumentNullException(nameof(names));
}
Names = names.ToArray();
}
///
/// Initializes a new instance of the class.
///
/// An array of allowed user names.
/// is .
[CLSCompliant(false)]
public RequireUserNameAttribute(params string[] names)
{
if (names is null)
{
throw new ArgumentNullException(nameof(names));
}
Names = names[..];
}
///
/// Gets a read-only view of the user names allowed to run this command.
///
/// A of representing the allowed user names.
public IReadOnlyList Names { get; }
///
protected internal override async Task PerformAsync(CommandContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
IUser user = await context.Avatar.GetUserAsync().ConfigureAwait(false);
return Names.Contains(user.Name);
}
}