Parameter preconditions and typereader overriding
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
|
||||
using System.Reflection;
|
||||
|
||||
namespace Discord.Commands
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Parameter)]
|
||||
public class OverrideTypeReaderAttribute : Attribute
|
||||
{
|
||||
private readonly TypeInfo _typeReaderTypeInfo = typeof(TypeReader).GetTypeInfo();
|
||||
|
||||
public Type TypeReader { get; }
|
||||
|
||||
public OverrideTypeReaderAttribute(Type overridenType)
|
||||
{
|
||||
if (!_typeReaderTypeInfo.IsAssignableFrom(overridenType.GetTypeInfo()))
|
||||
throw new ArgumentException($"{nameof(overridenType)} must inherit from {nameof(TypeReader)}");
|
||||
|
||||
TypeReader = overridenType;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Discord.Commands
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = true, Inherited = true)]
|
||||
public abstract class ParameterPreconditionAttribute : Attribute
|
||||
{
|
||||
public abstract Task<PreconditionResult> CheckPermissions(CommandContext context, ParameterInfo parameter, object value);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user