Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add array support for slash commands #340

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Commits on Sep 2, 2024

  1. feat(commands)!: Add variadic slash command args

    This commit changes how Remora.Discord.Commands maps slash commands,
    enabling support for arrays to be parsed and accepted, despite Discord
    STILL not having support for this.
    
    For better or worse, a snippet of code had to be removed:
    
    ```cs
    var collectionType = parameter.GetActualParameterType();
    
    if (!collectionType.IsCollection() && !collectionType.IsArray)
    {
        // Sanity check
        throw new InvalidOperationException("Collection parameter was not a collection.");
    }
    ```
    ^ For some reason, `.IsCollection()` returns...false? I gave up on
    trying to figure out why that was the case - the code still works fine
    and there's other validity checks elsewhere.
    
    BREAKING-CHANGE: Commands with the structure of `name__numbers`
    (e.g. `param__1`) are *no longer valid* and will get erased by the
    pre-parsing step that is a requisite to map arrays. This should be an
    absolutely niche case, but is still technically a breaking change, and
    should be documented as such.
    
    Some other things of note:
    
    - Attributes applied to the array apply to all elements in the array
     (this should go without saying, but hey)
    - `[Range]` controls the array's length; `Min` = required, `Max` = Length
     - If Min < Max, `Min` elements will be required and `Max - Min` elements
       will be optional. Max will coallecse to Min when unspecified.
    - Due to Discord's..questionable limitations, optional array parameters
      are placed at the end of the argument list for slash commands, but do
      preserve the order they're declared in relative to each other.
    VelvetToroyashi committed Sep 2, 2024
    Configuration menu
    Copy the full SHA
    445a56a View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    fb05a89 View commit details
    Browse the repository at this point in the history

Commits on Sep 4, 2024

  1. Configuration menu
    Copy the full SHA
    a0d7bc7 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    dbf749d View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    8274f94 View commit details
    Browse the repository at this point in the history
  4. Merge remote-tracking branch 'origin/velvet/feat/variadic-slash-argum…

    …ents' into velvet/feat/variadic-slash-arguments
    VelvetToroyashi committed Sep 4, 2024
    Configuration menu
    Copy the full SHA
    1c82c91 View commit details
    Browse the repository at this point in the history