Update commands with C#7 features (#689)
* C#7 features in commands, CommandInfo in ModuleBase * Update TypeReaders with C#7 features and IServiceProvider * Add best-choice command selection to CommandService * Normalize type reader scores correctly * Fix logic error and rebase onto dev * Change GetMethod for SetMethod in ReflectionUtils Should be checking against setters, not getters * Ensure args/params scores do not overwhelm Priority * Remove possibility of NaNs
This commit is contained in:
committed by
RogueException
parent
41222eafeb
commit
032aba9129
@@ -18,7 +18,7 @@ namespace Discord.Commands
|
||||
private static readonly System.Reflection.MethodInfo _convertParamsMethod = typeof(CommandInfo).GetTypeInfo().GetDeclaredMethod(nameof(ConvertParamsList));
|
||||
private static readonly ConcurrentDictionary<Type, Func<IEnumerable<object>, object>> _arrayConverters = new ConcurrentDictionary<Type, Func<IEnumerable<object>, object>>();
|
||||
|
||||
private readonly Func<ICommandContext, object[], IServiceProvider, Task> _action;
|
||||
private readonly Func<ICommandContext, object[], IServiceProvider, CommandInfo, Task> _action;
|
||||
|
||||
public ModuleInfo Module { get; }
|
||||
public string Name { get; }
|
||||
@@ -105,15 +105,17 @@ namespace Discord.Commands
|
||||
return PreconditionResult.FromSuccess();
|
||||
}
|
||||
|
||||
public async Task<ParseResult> ParseAsync(ICommandContext context, int startIndex, SearchResult searchResult, PreconditionResult preconditionResult = null)
|
||||
public async Task<ParseResult> ParseAsync(ICommandContext context, int startIndex, SearchResult searchResult, PreconditionResult preconditionResult = null, IServiceProvider services = null)
|
||||
{
|
||||
services = services ?? EmptyServiceProvider.Instance;
|
||||
|
||||
if (!searchResult.IsSuccess)
|
||||
return ParseResult.FromError(searchResult);
|
||||
if (preconditionResult != null && !preconditionResult.IsSuccess)
|
||||
return ParseResult.FromError(preconditionResult);
|
||||
|
||||
string input = searchResult.Text.Substring(startIndex);
|
||||
return await CommandParser.ParseArgs(this, context, input, 0).ConfigureAwait(false);
|
||||
return await CommandParser.ParseArgs(this, context, services, input, 0).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public Task<ExecuteResult> ExecuteAsync(ICommandContext context, ParseResult parseResult, IServiceProvider services)
|
||||
@@ -181,7 +183,7 @@ namespace Discord.Commands
|
||||
await Module.Service._cmdLogger.DebugAsync($"Executing {GetLogText(context)}").ConfigureAwait(false);
|
||||
try
|
||||
{
|
||||
await _action(context, args, services).ConfigureAwait(false);
|
||||
await _action(context, args, services, this).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -54,9 +54,10 @@ namespace Discord.Commands
|
||||
return PreconditionResult.FromSuccess();
|
||||
}
|
||||
|
||||
public async Task<TypeReaderResult> Parse(ICommandContext context, string input)
|
||||
public async Task<TypeReaderResult> Parse(ICommandContext context, string input, IServiceProvider services = null)
|
||||
{
|
||||
return await _reader.Read(context, input).ConfigureAwait(false);
|
||||
services = services ?? EmptyServiceProvider.Instance;
|
||||
return await _reader.Read(context, input, services).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public override string ToString() => Name;
|
||||
|
||||
Reference in New Issue
Block a user