fix: raise CommandExecuted on async errors

This resolves #1224.

Previously, raising CommandExecuted for errors was dependent on the
failed result making it back to ExecuteAsync. This is not possible with
async commands, which always pass back a succesful promise result,
rather than their fulfilled result.

This change moves the event invocation for exception'd ExecuteResults to
their source, and excludes ExecuteResult from the late event invocation
in CommandService#ExecuteAsync.
This commit is contained in:
Christopher Felegy
2018-12-31 13:36:30 -05:00
parent 552f34c30e
commit 497918edda
2 changed files with 2 additions and 1 deletions

View File

@@ -605,7 +605,7 @@ namespace Discord.Commands
//If we get this far, at least one parse was successful. Execute the most likely overload.
var chosenOverload = successfulParses[0];
var result = await chosenOverload.Key.ExecuteAsync(context, chosenOverload.Value, services).ConfigureAwait(false);
if (!result.IsSuccess && !(result is RuntimeResult)) // succesful results raise the event in CommandInfo#ExecuteInternalAsync (have to raise it there b/c deffered execution)
if (!result.IsSuccess && !(result is RuntimeResult || result is ExecuteResult)) // succesful results raise the event in CommandInfo#ExecuteInternalAsync (have to raise it there b/c deffered execution)
await _commandExecutedEvent.InvokeAsync(chosenOverload.Key.Command, context, result);
return result;
}

View File

@@ -274,6 +274,7 @@ namespace Discord.Commands
await Module.Service._cmdLogger.ErrorAsync(wrappedEx).ConfigureAwait(false);
var result = ExecuteResult.FromError(ex);
await Module.Service._commandExecutedEvent.InvokeAsync(this, context, result).ConfigureAwait(false);
if (Module.Service._throwOnError)
{