diff --git a/src/Discord.Net.Interactions/Info/Commands/AutocompleteCommandInfo.cs b/src/Discord.Net.Interactions/Info/Commands/AutocompleteCommandInfo.cs index 424c5d3a0..9e30c55f4 100644 --- a/src/Discord.Net.Interactions/Info/Commands/AutocompleteCommandInfo.cs +++ b/src/Discord.Net.Interactions/Info/Commands/AutocompleteCommandInfo.cs @@ -46,7 +46,7 @@ namespace Discord.Interactions /// protected override Task InvokeModuleEvent(IInteractionContext context, IResult result) => - CommandService.InvokeResultEventsAsync(this, context, result); + CommandService._autocompleteCommandExecutedEvent.InvokeAsync(this, context, result); /// protected override string GetLogString(IInteractionContext context) diff --git a/src/Discord.Net.Interactions/Info/Commands/ComponentCommandInfo.cs b/src/Discord.Net.Interactions/Info/Commands/ComponentCommandInfo.cs index 0b2849c77..22d6aba6c 100644 --- a/src/Discord.Net.Interactions/Info/Commands/ComponentCommandInfo.cs +++ b/src/Discord.Net.Interactions/Info/Commands/ComponentCommandInfo.cs @@ -84,7 +84,7 @@ namespace Discord.Interactions } protected override Task InvokeModuleEvent(IInteractionContext context, IResult result) - => CommandService.InvokeResultEventsAsync(this, context, result); + => CommandService._componentCommandExecutedEvent.InvokeAsync(this, context, result); protected override string GetLogString(IInteractionContext context) { diff --git a/src/Discord.Net.Interactions/Info/Commands/ContextCommands/ContextCommandInfo.cs b/src/Discord.Net.Interactions/Info/Commands/ContextCommands/ContextCommandInfo.cs index 94f5186f6..4c2e7af7d 100644 --- a/src/Discord.Net.Interactions/Info/Commands/ContextCommands/ContextCommandInfo.cs +++ b/src/Discord.Net.Interactions/Info/Commands/ContextCommands/ContextCommandInfo.cs @@ -46,6 +46,6 @@ namespace Discord.Interactions /// protected override Task InvokeModuleEvent (IInteractionContext context, IResult result) - => CommandService.InvokeResultEventsAsync(this, context, result); + => CommandService._contextCommandExecutedEvent.InvokeAsync(this, context, result); } } diff --git a/src/Discord.Net.Interactions/Info/Commands/ModalCommandInfo.cs b/src/Discord.Net.Interactions/Info/Commands/ModalCommandInfo.cs index eee0cba8f..4866bd1da 100644 --- a/src/Discord.Net.Interactions/Info/Commands/ModalCommandInfo.cs +++ b/src/Discord.Net.Interactions/Info/Commands/ModalCommandInfo.cs @@ -85,7 +85,7 @@ namespace Discord.Interactions /// protected override Task InvokeModuleEvent(IInteractionContext context, IResult result) - => CommandService.InvokeResultEventsAsync(this, context, result); + => CommandService._modalCommandExecutedEvent.InvokeAsync(this, context, result); /// protected override string GetLogString(IInteractionContext context) diff --git a/src/Discord.Net.Interactions/Info/Commands/SlashCommandInfo.cs b/src/Discord.Net.Interactions/Info/Commands/SlashCommandInfo.cs index 5584f4676..a123ac183 100644 --- a/src/Discord.Net.Interactions/Info/Commands/SlashCommandInfo.cs +++ b/src/Discord.Net.Interactions/Info/Commands/SlashCommandInfo.cs @@ -131,8 +131,8 @@ namespace Discord.Interactions return ParseResult.FromSuccess(readResult.Value); } - protected override Task InvokeModuleEvent(IInteractionContext context, IResult result) - => CommandService.InvokeResultEventsAsync(this, context, result); + protected override Task InvokeModuleEvent (IInteractionContext context, IResult result) + => CommandService._slashCommandExecutedEvent.InvokeAsync(this, context, result); protected override string GetLogString (IInteractionContext context) { diff --git a/src/Discord.Net.Interactions/InteractionService.cs b/src/Discord.Net.Interactions/InteractionService.cs index a12349d7e..deb6fa931 100644 --- a/src/Discord.Net.Interactions/InteractionService.cs +++ b/src/Discord.Net.Interactions/InteractionService.cs @@ -24,47 +24,41 @@ namespace Discord.Interactions public event Func Log { add { _logEvent.Add(value); } remove { _logEvent.Remove(value); } } internal readonly AsyncEvent> _logEvent = new (); - /// - /// Occurs when any type of interaction is executed. - /// - public event Func InteractionExecuted { add { _interactionExecutedEvent.Add(value); } remove { _interactionExecutedEvent.Remove(value); } } - private readonly AsyncEvent> _interactionExecutedEvent = new(); - /// /// Occurs when a Slash Command is executed. /// public event Func SlashCommandExecuted { add { _slashCommandExecutedEvent.Add(value); } remove { _slashCommandExecutedEvent.Remove(value); } } - private readonly AsyncEvent> _slashCommandExecutedEvent = new (); + internal readonly AsyncEvent> _slashCommandExecutedEvent = new (); /// /// Occurs when a Context Command is executed. /// public event Func ContextCommandExecuted { add { _contextCommandExecutedEvent.Add(value); } remove { _contextCommandExecutedEvent.Remove(value); } } - private readonly AsyncEvent> _contextCommandExecutedEvent = new (); + internal readonly AsyncEvent> _contextCommandExecutedEvent = new (); /// /// Occurs when a Message Component command is executed. /// public event Func ComponentCommandExecuted { add { _componentCommandExecutedEvent.Add(value); } remove { _componentCommandExecutedEvent.Remove(value); } } - private readonly AsyncEvent> _componentCommandExecutedEvent = new (); + internal readonly AsyncEvent> _componentCommandExecutedEvent = new (); /// /// Occurs when a Autocomplete command is executed. /// public event Func AutocompleteCommandExecuted { add { _autocompleteCommandExecutedEvent.Add(value); } remove { _autocompleteCommandExecutedEvent.Remove(value); } } - private readonly AsyncEvent> _autocompleteCommandExecutedEvent = new(); + internal readonly AsyncEvent> _autocompleteCommandExecutedEvent = new(); /// /// Occurs when a AutocompleteHandler is executed. /// public event Func AutocompleteHandlerExecuted { add { _autocompleteHandlerExecutedEvent.Add(value); } remove { _autocompleteHandlerExecutedEvent.Remove(value); } } - private readonly AsyncEvent> _autocompleteHandlerExecutedEvent = new(); + internal readonly AsyncEvent> _autocompleteHandlerExecutedEvent = new(); /// /// Occurs when a Modal command is executed. /// public event Func ModalCommandExecuted { add { _modalCommandExecutedEvent.Add(value); } remove { _modalCommandExecutedEvent.Remove(value); } } - private readonly AsyncEvent> _modalCommandExecutedEvent = new(); + internal readonly AsyncEvent> _modalCommandExecutedEvent = new(); private readonly ConcurrentDictionary _typedModuleDefs; private readonly CommandMap _slashCommandMap; @@ -725,7 +719,6 @@ namespace Discord.Interactions await _cmdLogger.DebugAsync($"Unknown slash command, skipping execution ({string.Join(" ", keywords).ToUpper()})"); await _slashCommandExecutedEvent.InvokeAsync(null, context, result).ConfigureAwait(false); - await InvokeResultEventsAsync(null, context, result).ConfigureAwait(false); return result; } return await result.Command.ExecuteAsync(context, services).ConfigureAwait(false); @@ -743,7 +736,6 @@ namespace Discord.Interactions await _cmdLogger.DebugAsync($"Unknown context command, skipping execution ({result.Text.ToUpper()})"); await _contextCommandExecutedEvent.InvokeAsync(null, context, result).ConfigureAwait(false); - await InvokeResultEventsAsync(null, context, result).ConfigureAwait(false); return result; } return await result.Command.ExecuteAsync(context, services).ConfigureAwait(false); @@ -758,7 +750,6 @@ namespace Discord.Interactions await _cmdLogger.DebugAsync($"Unknown custom interaction id, skipping execution ({input.ToUpper()})"); await _componentCommandExecutedEvent.InvokeAsync(null, context, result).ConfigureAwait(false); - await InvokeResultEventsAsync(null, context, result).ConfigureAwait(false); return result; } return await result.Command.ExecuteAsync(context, services, result.RegexCaptureGroups).ConfigureAwait(false); @@ -788,7 +779,6 @@ namespace Discord.Interactions await _cmdLogger.DebugAsync($"Unknown command name, skipping autocomplete process ({interaction.Data.CommandName.ToUpper()})"); await _autocompleteCommandExecutedEvent.InvokeAsync(null, context, commandResult).ConfigureAwait(false); - await InvokeResultEventsAsync(null, context, commandResult).ConfigureAwait(false); return commandResult; } @@ -804,37 +794,11 @@ namespace Discord.Interactions await _cmdLogger.DebugAsync($"Unknown custom interaction id, skipping execution ({input.ToUpper()})"); await _componentCommandExecutedEvent.InvokeAsync(null, context, result).ConfigureAwait(false); - await InvokeResultEventsAsync(null, context, result).ConfigureAwait(false); return result; } return await result.Command.ExecuteAsync(context, services, result.RegexCaptureGroups).ConfigureAwait(false); } - internal async Task InvokeResultEventsAsync(ICommandInfo info, IInteractionContext context, IResult result) - { - await _interactionExecutedEvent.InvokeAsync(null, context, result).ConfigureAwait(false); - if (info is not null) - { - switch (info) - { - case SlashCommandInfo slashCmd: - await _slashCommandExecutedEvent.InvokeAsync(slashCmd, context, result).ConfigureAwait(false); - return; - case ContextCommandInfo ctxCmd: - await _contextCommandExecutedEvent.InvokeAsync(ctxCmd, context, result).ConfigureAwait(false); - return; - case ComponentCommandInfo component: - await _componentCommandExecutedEvent.InvokeAsync(component, context, result).ConfigureAwait(false); - return; - case AutocompleteCommandInfo autocomplete: - await _autocompleteCommandExecutedEvent.InvokeAsync(autocomplete, context, result).ConfigureAwait(false); - return; - default: - throw new InvalidOperationException("No event has been designated to this interaction result."); - } - } - } - internal TypeConverter GetTypeConverter(Type type, IServiceProvider services = null) => _typeConverterMap.Get(type, services);