Comments (10)
Okay I've read some docs and from my understanding buttons cannot expire. Each button click creates a new interaction event, what expires is the ReplyHook after 15mins. As I am thinking about this right now, this would mean that we only have 15mins to remove a button? Because we can only edit the message (and its components) for 15mins. However we can always remove the button listener in which case #120 will handle the situation.
Still we should provide an option to remove buttons after a certain amount of time. I think @aless2003 proposal is a good one. However I'd like to modifiy it a little bit. Instead of creating a new class, we can just define a method inside the interaction class.
@Interaction
public class MyCommand {
//Commands...
@Button("Click here")
@Expiration(handler = "onHandleExpiration", time = 10, unit=TimeUnit.SECONDS)
public void onClickButton(CommandEvent event) {
event.reply("Hey you clicked!");
}
@ExpirationHandler
public void onHandleExpiration(ButtonExpirationEvent event) {
event.removeButton();
}
}
This, however adds overhead so maybe my idea of introducing different expiring strategies actually wasn't the worst. I could think about the following strategies:
DELETE
: deletes the original message
CLEAR
: removes the component
CLEAR_ALL
: removes all components
KEEP
: keeps the component but unregisters its listener. This will also be the fallback strategy after 15 minutes have passed.
from jda-commands.
turns out that this is a rather complex problem. I've moved the current state of implementation to another branch and will focus on different issues for now
from jda-commands.
@stijnb1234 @aless2003 @lus (and all the other contributers) any thoughts on this one?
from jda-commands.
I'd say specifying some kind of callback which gets executed on expiration should be possible to just handle this individually.
from jda-commands.
The question is how we integrate this callback into the interaction class
Example Button Code
@Interaction
public class ButtonCommand {
@SlashCommand
public void onCommand(CommandEvent event) {
event.withButtons("onButton").reply("Hello");
}
@Button("Click me!")
public void onButton(CommandEvent event) {
event.reply("You've clicked me");
}
}
I think that a generic interface like ButtonExpirationHandler
would be a bad solution since we want high friction between expiration handling and button defining.
Another question is if buttons always need to expire. But on this one I'm not sure what discords limitations are.
Also I'd like to avoid things like @Button(expiration = 10, unit = TimeUnit.MINUTES, strategy=ExpirationStrategy.DELETE)
from jda-commands.
I think the best option is to auto-remove the buttons after they expire, unless the Programmer specifies otherwise. It would keep the Programming experience quite easy. Additionally, it would be less confusing to a User as when there's no Button, you don't have to wonder as to why something doesn't work.
As for the part if it should expire, I would keep whatever the default behavior is for those in JDA and let the Programmer change it as needed. I could Imagine something like
@Interaction
public class MyCommand {
//Commands...
@Button("Click here")
@Expiering(handler=MyHandler.class, time = 10, unit=TimeUnit.Seconds)
public void onClickButton(CommandEvent event) {
event.reply("Hey you clicked!");
}
}
HyHandler.class
public class MyHandler implements ExpirationHandler {
@Override
public void handle(CommandEvent event) {
event.reply("Your time has run out");
event.getMessage().delete().queue();
}
}
Not sure if CommandEvent is the best argument for the handle method though. We could also combine @Expiring
with @Button
, depending on whether other elements can expire. I havenโt looked too much into Interactions yet, so let me know what you think.
from jda-commands.
I agree with @aless2003, I think that's the best way to implement this.
from jda-commands.
I see a problem in this proposed solution.
We create one instance of the interaction class per invocation, making it very straightforward to store the state of this particular invocation as local class variables.
If we create a new instance of an ExpirationHandler
whenever the button/interaction has expired, we would lose this state in that class.
from jda-commands.
Couldn't we create just one instance of each ExpirationHandler
needed in a particular class when checking the Annotations and just reuse this instance over and over again?
from jda-commands.
Related Issues (20)
- [BUG] Reply message always ephemeral HOT 1
- [FEATURE] make Dependency Injector an interface
- [FEATURE] add setErrorConsumer
- [BUG] reimplement CooldownFilter
- [FEATURE] Handle unknown interactions HOT 2
- Add support for command groups & Modals HOT 4
- No function to send modals HOT 1
- [BUG] Some commands are not registering HOT 13
- [BUG] Command execution fails with IndexOutOfBoundsException HOT 3
- [QUESTION] How do I make commandautocompleteevent work? HOT 15
- [BUG] DefaultValues have no effect on SelectMenus
- Would be nice to have more documentation on buttons and modals
- Error in discord, but not in console. HOT 12
- [FEATURE] Ignore non-jda-commands interactions
- [FEATURE] Add components API for usage outside of commands
- [FEATURE] Implement static interactions
- [FEATURE] Add i18n for EmbedCache
- interaction of non-jda-commands interactions isnt ignored. HOT 1
- Where to find "log console" HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jda-commands.