Skip to content

Implement pre-execution handlers#296

Open
KubaZ2 wants to merge 3 commits intoalphafrom
feature/hosting-pre-execution-handlers
Open

Implement pre-execution handlers#296
KubaZ2 wants to merge 3 commits intoalphafrom
feature/hosting-pre-execution-handlers

Conversation

@KubaZ2
Copy link
Member

@KubaZ2 KubaZ2 commented Mar 7, 2026

Fixes #290

@github-actions
Copy link

github-actions bot commented Mar 7, 2026

The documentation preview is available at https://preview.netcord.dev/296.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements pre-execution handlers for all command/interaction handler types in NetCord.Hosting.Services, addressing issue #290 (pre and post-execution events). It introduces a PreExecutionResult discriminated union and corresponding handler interfaces/defaults, allowing users to intercept and optionally abort command/interaction execution.

Changes:

  • New PreExecutionResult hierarchy (ContinuePreExecutionResult, SkipPreExecutionResult) enabling return-type-driven flow control from pre-execution handlers.
  • Interfaces and default implementations for pre-execution handlers across all four handler types: application commands, autocomplete interactions, component interactions, and text commands.
  • Integration of the pre-execution handlers into all four existing handler execution paths, including exception handling and early exit on Skip.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
CommandPreExecutionResult.cs Defines the closed PreExecutionResult type hierarchy (Continue/Skip)
ApplicationCommands/IApplicationCommandPreExecutionHandler.cs New interface for application command pre-execution
ApplicationCommands/ApplicationCommandPreExecutionHandler.cs Default implementation: logs command name, returns Continue
ApplicationCommands/IAutocompleteInteractionPreExecutionHandler.cs New interface for autocomplete pre-execution
ApplicationCommands/AutocompleteInteractionPreExecutionHandler.cs Default implementation: logs autocomplete command name, returns Continue
ApplicationCommands/ApplicationCommandServiceOptions.cs Adds PreExecutionHandler and AutocompletePreExecutionHandler options
ApplicationCommands/ApplicationCommandInteractionHandler.cs Integrates pre-execution handler into the app command execution path
ApplicationCommands/AutocompleteInteractionHandler.cs Integrates pre-execution handler into the autocomplete execution path
Commands/ICommandPreExecutionHandler.cs New interface for text command pre-execution
Commands/CommandPreExecutionHandler.cs Default implementation: logs message content, returns Continue
Commands/CommandServiceOptions.cs Adds PreExecutionHandler option
Commands/CommandHandler.cs Integrates pre-execution handler into the text command execution path
ComponentInteractions/ICommandPreExecutionHandler.cs Misnamed file – contains IComponentInteractionPreExecutionHandler<TContext> (should be IComponentInteractionPreExecutionHandler.cs)
ComponentInteractions/ComponentInteractionPreExecutionHandler.cs Default implementation: logs custom ID, returns Continue
ComponentInteractions/ComponentInteractionServiceOptions.cs Adds PreExecutionHandler option
ComponentInteractions/ComponentInteractionHandler.cs Integrates pre-execution handler into the component interaction execution path

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@KubaZ2 KubaZ2 requested a review from Copilot March 7, 2026 16:09
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pre and post-execution events

2 participants