Browse Source

Added CommandService.CommandExecuted (#747)

tags/2.0.0-beta
Christopher F GitHub 7 years ago
parent
commit
e991715bac
2 changed files with 10 additions and 2 deletions
  1. +3
    -0
      src/Discord.Net.Commands/CommandService.cs
  2. +7
    -2
      src/Discord.Net.Commands/Info/CommandInfo.cs

+ 3
- 0
src/Discord.Net.Commands/CommandService.cs View File

@@ -16,6 +16,9 @@ namespace Discord.Commands
public event Func<LogMessage, Task> Log { add { _logEvent.Add(value); } remove { _logEvent.Remove(value); } }
internal readonly AsyncEvent<Func<LogMessage, Task>> _logEvent = new AsyncEvent<Func<LogMessage, Task>>();

public event Func<CommandInfo, ICommandContext, IResult, Task> CommandExecuted { add { _commandExecutedEvent.Add(value); } remove { _commandExecutedEvent.Remove(value); } }
internal readonly AsyncEvent<Func<CommandInfo, ICommandContext, IResult, Task>> _commandExecutedEvent = new AsyncEvent<Func<CommandInfo, ICommandContext, IResult, Task>>();

private readonly SemaphoreSlim _moduleLock;
private readonly ConcurrentDictionary<Type, ModuleInfo> _typedModuleDefs;
private readonly ConcurrentDictionary<Type, ConcurrentDictionary<Type, TypeReader>> _typeReaders;


+ 7
- 2
src/Discord.Net.Commands/Info/CommandInfo.cs View File

@@ -188,17 +188,22 @@ namespace Discord.Commands
if (task is Task<IResult> resultTask)
{
var result = await resultTask.ConfigureAwait(false);
await Module.Service._commandExecutedEvent.InvokeAsync(this, context, result).ConfigureAwait(false);
if (result is RuntimeResult execResult)
return execResult;
}
else if (task is Task<ExecuteResult> execTask)
{
return await execTask.ConfigureAwait(false);
var result = await execTask.ConfigureAwait(false);
await Module.Service._commandExecutedEvent.InvokeAsync(this, context, result).ConfigureAwait(false);
return result;
}
else
await task.ConfigureAwait(false);

return ExecuteResult.FromSuccess();
var executeResult = ExecuteResult.FromSuccess();
await Module.Service._commandExecutedEvent.InvokeAsync(this, context, executeResult).ConfigureAwait(false);
return executeResult;
}
catch (Exception ex)
{


Loading…
Cancel
Save