-
-
Notifications
You must be signed in to change notification settings - Fork 735
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 JDA#listenOnce
#2683
Add JDA#listenOnce
#2683
Conversation
There is an |
This would make things more complicated, if someone has a use case where you'd need to listen once for an event across all shards, let me know |
Just a quick thought, but I believe these would also be benifical. 💕 <E extends GenericEvent> Task<E> listenOnce(Class<E> type, Predicate<? super E> filter);
<E extends GenericEvent> Task<E> listenOnce(Class<E> type, Predicate<? super E> filter, Duration duration, @Nullable Runnable callback); Otherwise at least some way to jda.listenOnce(new SomethingCommonlyImplemented(argA, argB, etc)); |
After discussing:
public abstract class OnceFactory<E extends GenericEvent> {
private final JDA jda;
public OnceFactory(JDA jda) {
this.jda = jda;
}
protected Class<E> getType();
protected void configure(Once.Builder<E> builder);
public Task<E> create() {
final var builder = jda.listenOnce(getType());
configure(builder);
return builder.submit();
}
} |
Co-authored-by: Florian Spieß <business@minn.dev>
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Type | Update | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---|---|---| | debian | final | digest | `5f7d566` -> `2ccc7e3` | | | | | | maven | stage | digest | `6bfb613` -> `7bec384` | | | | | | rust | stage | minor | `1.79.0-bookworm` -> `1.80.1-bookworm` | [![age](https://developer.mend.io/api/mc/badges/age/docker/rust/1.80.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/docker/rust/1.80.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/docker/rust/1.79.0/1.80.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/docker/rust/1.79.0/1.80.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | | [net.dv8tion:JDA](https://github.com/discord-jda/JDA) | compile | patch | `5.0.1` -> `5.0.2` | [![age](https://developer.mend.io/api/mc/badges/age/maven/net.dv8tion:JDA/5.0.2?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/maven/net.dv8tion:JDA/5.0.2?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/maven/net.dv8tion:JDA/5.0.1/5.0.2?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/maven/net.dv8tion:JDA/5.0.1/5.0.2?slim=true)](https://docs.renovatebot.com/merge-confidence/) | | [com.github.sealedtx:java-youtube-downloader](https://github.com/sealedtx/java-youtube-downloader) | compile | patch | `3.2.3` -> `3.2.4` | [![age](https://developer.mend.io/api/mc/badges/age/maven/com.github.sealedtx:java-youtube-downloader/3.2.4?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/maven/com.github.sealedtx:java-youtube-downloader/3.2.4?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/maven/com.github.sealedtx:java-youtube-downloader/3.2.3/3.2.4?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/maven/com.github.sealedtx:java-youtube-downloader/3.2.3/3.2.4?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>discord-jda/JDA (net.dv8tion:JDA)</summary> ### [`v5.0.2`](https://github.com/discord-jda/JDA/releases/tag/v5.0.2): | Single time event listener ### Overview This release includes some bug fixes as well as a new event listener feature to add a one-time-use event listener. ##### Once Event Listener ([#​2683](https://github.com/discord-jda/JDA/issues/2683)) A common problem that developers run into, is "waiting" for a specific event in the context of some command. For instance, waiting for a user to add a reaction or reply with a message in response to some prompt. This can now be achieved using the new [listenOnce](https://docs.jda.wiki/net/dv8tion/jda/api/JDA.html#listenOnce\(java.lang.Class\)) event listener: ```java // listen for a message event jda.listenOnce(MessageReceivedEvent.class) // filter for specific event .filter(event -> event.getChannel().equals(channel)) .filter(event -> event.getAuthor().equals(user)) // handle timeout .timeout(timeout, () -> hook.editOriginal("Timeout!").queue()) // subscribe to first event that matches filters .subscribe(event -> { hook.editOriginal("You sent: " + event.getMessage().getContentRaw()).queue(); }); ``` #### New Features - Add `TeamMember.RoleType` by [@​freya022](https://github.com/freya022) in [https://github.com/discord-jda/JDA/pull/2703](https://github.com/discord-jda/JDA/pull/2703) - Add abstract `createCopy` method in `SelectMenu` by [@​Kaktushose](https://github.com/Kaktushose) in [https://github.com/discord-jda/JDA/pull/2684](https://github.com/discord-jda/JDA/pull/2684) - Add `JDA#listenOnce` by [@​freya022](https://github.com/freya022) in [https://github.com/discord-jda/JDA/pull/2683](https://github.com/discord-jda/JDA/pull/2683) - Add support for profile automod by [@​MinnDevelopment](https://github.com/MinnDevelopment) in [https://github.com/discord-jda/JDA/pull/2580](https://github.com/discord-jda/JDA/pull/2580) #### Changes - Expand list of retried http error codes by [@​MinnDevelopment](https://github.com/MinnDevelopment) in [https://github.com/discord-jda/JDA/pull/2710](https://github.com/discord-jda/JDA/pull/2710) - Update to Jackson 2.17.2 by [@​freya022](https://github.com/freya022) in [https://github.com/discord-jda/JDA/pull/2695](https://github.com/discord-jda/JDA/pull/2695) #### Bug Fixes - Fix deserialization of interaction components by [@​WitchBoo](https://github.com/WitchBoo) in [https://github.com/discord-jda/JDA/pull/2711](https://github.com/discord-jda/JDA/pull/2711) **Full Changelog**: discord-jda/JDA@v5.0.1...v5.0.2 ### Installation #### Gradle ```gradle repositories { mavenCentral() } dependencies { implementation("net.dv8tion:JDA:5.0.2") } ``` #### Maven ```xml <dependency> <groupId>net.dv8tion</groupId> <artifactId>JDA</artifactId> <version>5.0.2</version> </dependency> ``` </details> <details> <summary>sealedtx/java-youtube-downloader (com.github.sealedtx:java-youtube-downloader)</summary> ### [`v3.2.4`](https://github.com/sealedtx/java-youtube-downloader/releases/tag/3.2.4) [Compare Source](https://github.com/sealedtx/java-youtube-downloader/compare/3.2.3...3.2.4) added missing itags </details> --- ### Configuration 📅 **Schedule**: Branch creation - "before 6am on saturday" in timezone Europe/Berlin, Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 👻 **Immortal**: This PR will be recreated if closed unmerged. Get [config help](https://github.com/renovatebot/renovate/discussions) if that's undesired. --- - [ ] If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View the [repository job log](https://developer.mend.io/github/SvenKirschbaum/musikbot-client).
Pull Request Etiquette
Changes
Closes Issue: NaN
Description
Adds an helper method to listen for an event, once.
Example: Listening to a message from a channel and a user, after using a slash command: