Skip to content

feat: Add precondition system for command validation#61

Merged
vrdons merged 4 commits intomainfrom
feat/precondition
Mar 13, 2026
Merged

feat: Add precondition system for command validation#61
vrdons merged 4 commits intomainfrom
feat/precondition

Conversation

@fhyrox
Copy link
Member

@fhyrox fhyrox commented Mar 8, 2026

No description provided.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances command validation by implementing a new precondition system. This system allows for custom checks to be run before a command executes, ensuring that commands are only processed when specific criteria are met. It improves user experience by providing immediate and informative feedback when commands are used improperly or without the necessary permissions. Additionally, it includes minor updates to dependency metadata and an example script for easier testing.

Highlights

  • Precondition System: Introduced a new system for defining and applying preconditions to commands, allowing for validation checks before command execution.
  • Command Integration: Commands can now register one or more preconditions, which are automatically checked when the command is invoked via interaction or message.
  • Error Handling: If a precondition fails, a specified error message is sent back to the user, providing clear feedback on why the command could not be executed.
  • Example Preconditions: Added example preconditions, including an 'adminOnly' check for administrator permissions and a generic 'error' precondition for demonstration.
  • Dependency Metadata Update: Modified package-lock.json to remove the peer: true flag from several dependency entries, which can affect how packages are resolved and installed.
Changelog
  • examples/basic_client/commands/report.cjs
    • Added an 'error' precondition to the report command for testing the new system.
  • examples/basic_client/preconditions/adminOnly.cjs
    • Created a new precondition that verifies if the command invoker possesses administrator permissions.
  • examples/basic_client/preconditions/error.cjs
    • Created a new precondition that is designed to always fail, demonstrating error handling.
  • package-lock.json
    • Removed the 'peer: true' property from various dependency entries, including those related to @discordjs and @sapphire packages.
  • package.json
    • Added a new example script to facilitate running the basic client application.
  • src/events/interaction.ts
    • Integrated precondition checks for interaction-based commands.
    • Implemented logic to reply with an ephemeral error message if any precondition fails.
  • src/events/message.ts
    • Integrated precondition checks for message-based commands.
    • Implemented logic to reply with an error message and delete it after a short period if any precondition fails.
  • src/structures/builder/Command.ts
    • Added a preconditions array to store registered preconditions.
    • Implemented addPrecondition and addPreconditions methods to register new preconditions.
    • Added checkPreconditions method to asynchronously evaluate all registered preconditions.
  • src/structures/builder/Precondition.ts
    • Created a new Precondition class to encapsulate the name, error message, and execution logic of a precondition.
  • types/precondition.d.ts
    • Defined the IPrecondition interface, specifying the structure for precondition objects.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a robust precondition system for command validation, which is an excellent feature for the framework. However, a security concern was identified regarding the handling of mentions in precondition error messages for message-based commands, which could be exploited for mention spam. Additionally, I've included a few suggestions to enhance conciseness and make better use of the discord.js API within the example files.

@fhyrox fhyrox requested a review from vrdons March 8, 2026 20:16
options

BREAKING CHANGE: Preconditions must now return `[boolean]` or
`[boolean, TranslateOptions]` instead of just `boolean`. The
`errorMessage` property has been removed from IPrecondition. Error
messages are now resolved via i18n using the key
`error:precondition.{name}`.
@vrdons vrdons changed the title feature: Add precondition system for command validation feat: Add precondition system for command validation Mar 13, 2026
@vrdons
Copy link
Member

vrdons commented Mar 13, 2026

Cok ii review yapionus ;3

@vrdons vrdons merged commit fac72ab into main Mar 13, 2026
8 checks passed
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.

2 participants