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

feat: add wildcard components #188

Merged
merged 7 commits into from
Nov 25, 2021

Conversation

sudojunior
Copy link
Contributor

@sudojunior sudojunior commented Nov 22, 2021

This extends further from #145 by adding a listener for all components on a message as a wildcard - the component used can be determined by ctx.custom_id.

  • Method Docs / Descriptions

Added

  • MessageInteractionContext#registerWildcardComponent(message_id, callback, expiration, onExpired)
  • MessageInteractionContext#unregisterWildcardComponent(message_id)

Wildcard components use the invoking message ID with an asterisk (*) to prevent possible conflicts with existing registered components.

For context sake, this was implemented with eda121e (Gist Component) with a specific use for ephemeral components (and having it unregister itself immediately before invoking the callback).

@sudojunior sudojunior requested a review from Snazzah as a code owner November 22, 2021 20:19
@Snazzah Snazzah added scope: components This has something to do with components semver: minor PRs that contain new features and will be on the next minor release type: enhancement New feature or request labels Nov 23, 2021
@sudojunior
Copy link
Contributor Author

I could have also added a predicate return on the register method, which would have ended up looking like...

class MessageInteractionContext {
  // ...
  registerWildcardComponent(message_id: string, /* ... */) {
    // ...
    return () => this.unregisterWildcardComponent(message_id);
  }
}

It is already so far against the existing style of the library, but I figured it'd be useful - similar to how I handled it in the demo.

const unref = this.registerWildcardComponent('0123456789', ctx => {
  // check interaction
  unref(); // remove after pre-conditions pass
  // continue
});

@Snazzah
Copy link
Owner

Snazzah commented Nov 24, 2021

@sudojunior Sounds good, would have to change the other functions to match.

…nteractionContext

* registerComponent
* registerComponentFrom
* registerWildcardComponent
* Unsure if this is what was meant by the review comment... (or if i've covered all aspects)
…MessageInteractionContext"

This reverts commit b7a4169.
@Snazzah Snazzah changed the title feat: add wildcard components ({msg}-*) feat: add wildcard components Nov 25, 2021
@Snazzah Snazzah merged commit 769d2c1 into Snazzah:master Nov 25, 2021
@sudojunior sudojunior deleted the feature/wildcard-components branch March 9, 2022 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: components This has something to do with components semver: minor PRs that contain new features and will be on the next minor release type: enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants