Skip to content
This repository has been archived by the owner on Dec 1, 2021. It is now read-only.

Interaction Framework #19

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

Conversation

jasonlessenich
Copy link
Member

@jasonlessenich jasonlessenich commented Nov 13, 2021

This PR adds the Interaction Framework which was mentioned in #8

Example

new InteractionHandlerBuilder(responseBuilder)
     .addButtons(
   	  new ButtonAction("Dummy Button", ButtonStyle.PRIMARY)
   	    .handledBy(ButtonExample.class)
   	    .addParam(interaction.getUser().getId()),
   	  new ButtonAction("Dummy Button²", ButtonStyle.PRIMARY)
   	    .handledBy(ButtonExample.class)
   	    .addParam(interaction.getCommandId()))
     .addSelectionMenus(
          new SelectMenuAction()
   	    .handledBy(SelectMenuExample.class)
   	    .addOptions(
               SelectMenuOption.create("Label", "Value"),
               SelectMenuOption.create("Label²", "Value²"))
   	    .setMinValue(2)
   	    .setMaxValue(10)
   	    .setPlaceholder("Choose one!")
     ).getResponseBuilder();

@jasonlessenich jasonlessenich self-assigned this Nov 13, 2021
@jasonlessenich jasonlessenich added the Interaction Framework Related to the interaction framework. label Nov 13, 2021
@jasonlessenich jasonlessenich linked an issue Nov 13, 2021 that may be closed by this pull request
2 tasks
*/
public ButtonAction(String label, ButtonStyle buttonStyle) {
this.params = new ArrayList<>();
this.label = label;
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a check to make sure that the label does not contain the ':' character. Throw an IllegalArgumentException if so, since this will mess up handling the interaction later on.

* @return the current instance in order to allow chain call methods.
*/
public ButtonAction addParam(Object param) {
params.add(String.valueOf(param));
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, check that the param's string representation cannot contain the ':' symbol. Also it would probably be nicer to just require a String parameter instead of accepting any object and then converting it into a string. Also this doesn't seem to support the notion of type-checked or named parameters, which is something that would make handling the button interactions much easier, since then each developer who adds an interaction wouldn't be responsible for their own manual parsing and serializing of possibly complex data.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Interaction Framework Related to the interaction framework.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create Button Interaction Framework
2 participants