|
@@ -1,7 +1,10 @@ |
|
|
using System; |
|
|
using System; |
|
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
|
using System.Collections.Immutable; |
|
|
using System.Diagnostics; |
|
|
using System.Diagnostics; |
|
|
using System.Reflection; |
|
|
using System.Reflection; |
|
|
using System.Threading.Tasks; |
|
|
using System.Threading.Tasks; |
|
|
|
|
|
using Discord.Commands.Attributes; |
|
|
|
|
|
|
|
|
namespace Discord.Commands |
|
|
namespace Discord.Commands |
|
|
{ |
|
|
{ |
|
@@ -18,6 +21,7 @@ namespace Discord.Commands |
|
|
public bool IsMultiple { get; } |
|
|
public bool IsMultiple { get; } |
|
|
public Type ElementType { get; } |
|
|
public Type ElementType { get; } |
|
|
public object DefaultValue { get; } |
|
|
public object DefaultValue { get; } |
|
|
|
|
|
public IReadOnlyList<ParameterPreconditionAttribute> Preconditions { get; } |
|
|
|
|
|
|
|
|
public CommandParameter(ParameterInfo source, string name, string summary, Type type, TypeReader reader, bool isOptional, bool isRemainder, bool isMultiple, object defaultValue) |
|
|
public CommandParameter(ParameterInfo source, string name, string summary, Type type, TypeReader reader, bool isOptional, bool isRemainder, bool isMultiple, object defaultValue) |
|
|
{ |
|
|
{ |
|
@@ -30,6 +34,7 @@ namespace Discord.Commands |
|
|
IsRemainder = isRemainder; |
|
|
IsRemainder = isRemainder; |
|
|
IsMultiple = isMultiple; |
|
|
IsMultiple = isMultiple; |
|
|
DefaultValue = defaultValue; |
|
|
DefaultValue = defaultValue; |
|
|
|
|
|
Preconditions = BuildPreconditions(source); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public async Task<TypeReaderResult> Parse(CommandContext context, string input) |
|
|
public async Task<TypeReaderResult> Parse(CommandContext context, string input) |
|
@@ -37,6 +42,23 @@ namespace Discord.Commands |
|
|
return await _reader.Read(context, input).ConfigureAwait(false); |
|
|
return await _reader.Read(context, input).ConfigureAwait(false); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public async Task<PreconditionResult> CheckPreconditions(CommandContext context, IDependencyMap map = null) |
|
|
|
|
|
{ |
|
|
|
|
|
foreach (ParameterPreconditionAttribute precondition in Preconditions) |
|
|
|
|
|
{ |
|
|
|
|
|
var result = await precondition.CheckPermissions(context, this, map).ConfigureAwait(false); |
|
|
|
|
|
if (!result.IsSuccess) |
|
|
|
|
|
return result; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return PreconditionResult.FromSuccess(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private IReadOnlyList<ParameterPreconditionAttribute> BuildPreconditions(ParameterInfo paramInfo) |
|
|
|
|
|
{ |
|
|
|
|
|
return paramInfo.GetCustomAttributes<ParameterPreconditionAttribute>().ToImmutableArray(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public override string ToString() => Name; |
|
|
public override string ToString() => Name; |
|
|
private string DebuggerDisplay => $"{Name}{(IsOptional ? " (Optional)" : "")}{(IsRemainder ? " (Remainder)" : "")}"; |
|
|
private string DebuggerDisplay => $"{Name}{(IsOptional ? " (Optional)" : "")}{(IsRemainder ? " (Remainder)" : "")}"; |
|
|
} |
|
|
} |
|
|