Cleaned up command builders and async func names
This commit is contained in:
@@ -39,17 +39,21 @@ namespace Discord.Commands
|
||||
|
||||
RunMode = builder.RunMode;
|
||||
Priority = builder.Priority;
|
||||
|
||||
if (module.Aliases.Count != 0)
|
||||
Aliases = module.Aliases.Permutate(builder.Aliases, (first, second) => first + " " + second).ToImmutableArray();
|
||||
else
|
||||
Aliases = builder.Aliases.ToImmutableArray();
|
||||
|
||||
Aliases = module.Aliases.Permutate(builder.Aliases, (first, second) => first + " " + second).ToImmutableArray();
|
||||
Preconditions = builder.Preconditions.ToImmutableArray();
|
||||
|
||||
Parameters = builder.Parameters.Select(x => x.Build(this, service)).ToImmutableArray();
|
||||
HasVarArgs = builder.Parameters.Count > 0 ? builder.Parameters[builder.Parameters.Count - 1].Multiple : false;
|
||||
Parameters = builder.Parameters.Select(x => x.Build(this)).ToImmutableArray();
|
||||
HasVarArgs = builder.Parameters.Count > 0 ? builder.Parameters[builder.Parameters.Count - 1].IsMultiple : false;
|
||||
|
||||
_action = builder.Callback;
|
||||
}
|
||||
|
||||
public async Task<PreconditionResult> CheckPreconditions(CommandContext context, IDependencyMap map = null)
|
||||
public async Task<PreconditionResult> CheckPreconditionsAsync(CommandContext context, IDependencyMap map = null)
|
||||
{
|
||||
if (map == null)
|
||||
map = DependencyMap.Empty;
|
||||
@@ -71,13 +75,13 @@ namespace Discord.Commands
|
||||
return PreconditionResult.FromSuccess();
|
||||
}
|
||||
|
||||
public async Task<ParseResult> Parse(CommandContext context, SearchResult searchResult, PreconditionResult? preconditionResult = null)
|
||||
public async Task<ParseResult> ParseAsync(CommandContext context, SearchResult searchResult, PreconditionResult? preconditionResult = null)
|
||||
{
|
||||
if (!searchResult.IsSuccess)
|
||||
return ParseResult.FromError(searchResult);
|
||||
if (preconditionResult != null && !preconditionResult.Value.IsSuccess)
|
||||
return ParseResult.FromError(preconditionResult.Value);
|
||||
|
||||
|
||||
string input = searchResult.Text;
|
||||
var matchingAliases = Aliases.Where(alias => input.StartsWith(alias));
|
||||
|
||||
@@ -114,9 +118,9 @@ namespace Discord.Commands
|
||||
paramList[i] = parseResult.ParamValues[i].Values.First().Value;
|
||||
}
|
||||
|
||||
return Execute(context, argList, paramList, map);
|
||||
return ExecuteAsync(context, argList, paramList, map);
|
||||
}
|
||||
public async Task<ExecuteResult> Execute(CommandContext context, IEnumerable<object> argList, IEnumerable<object> paramList, IDependencyMap map)
|
||||
public async Task<ExecuteResult> ExecuteAsync(CommandContext context, IEnumerable<object> argList, IEnumerable<object> paramList, IDependencyMap map)
|
||||
{
|
||||
if (map == null)
|
||||
map = DependencyMap.Empty;
|
||||
@@ -163,7 +167,7 @@ namespace Discord.Commands
|
||||
|
||||
if (HasVarArgs)
|
||||
{
|
||||
var func = _arrayConverters.GetOrAdd(Parameters[Parameters.Count - 1].ParameterType, t =>
|
||||
var func = _arrayConverters.GetOrAdd(Parameters[Parameters.Count - 1].Type, t =>
|
||||
{
|
||||
var method = _convertParamsMethod.MakeGenericMethod(t);
|
||||
return (Func<IEnumerable<object>, object>)method.CreateDelegate(typeof(Func<IEnumerable<object>, object>));
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
@@ -41,11 +40,11 @@ namespace Discord.Commands
|
||||
Stack<ModuleBuilder> builderStack = new Stack<ModuleBuilder>();
|
||||
builderStack.Push(builder);
|
||||
|
||||
ModuleBuilder parent = builder.ParentModule;
|
||||
ModuleBuilder parent = builder.Parent;
|
||||
while (parent != null)
|
||||
{
|
||||
builderStack.Push(parent);
|
||||
parent = parent.ParentModule;
|
||||
parent = parent.Parent;
|
||||
}
|
||||
|
||||
while (builderStack.Count() > 0)
|
||||
@@ -82,7 +81,7 @@ namespace Discord.Commands
|
||||
while (parent != null)
|
||||
{
|
||||
result.AddRange(parent.Preconditions);
|
||||
parent = parent.ParentModule;
|
||||
parent = parent.Parent;
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -16,11 +16,11 @@ namespace Discord.Commands
|
||||
|
||||
Name = builder.Name;
|
||||
Summary = builder.Summary;
|
||||
IsOptional = builder.Optional;
|
||||
IsRemainder = builder.Remainder;
|
||||
IsMultiple = builder.Multiple;
|
||||
IsOptional = builder.IsOptional;
|
||||
IsRemainder = builder.IsRemainder;
|
||||
IsMultiple = builder.IsMultiple;
|
||||
|
||||
ParameterType = builder.ParameterType;
|
||||
Type = builder.ParameterType;
|
||||
DefaultValue = builder.DefaultValue;
|
||||
|
||||
_reader = builder.TypeReader;
|
||||
@@ -32,7 +32,7 @@ namespace Discord.Commands
|
||||
public bool IsOptional { get; }
|
||||
public bool IsRemainder { get; }
|
||||
public bool IsMultiple { get; }
|
||||
public Type ParameterType { get; }
|
||||
public Type Type { get; }
|
||||
public object DefaultValue { get; }
|
||||
|
||||
public async Task<TypeReaderResult> Parse(CommandContext context, string input)
|
||||
|
||||
Reference in New Issue
Block a user