11package net .javadiscord .javabot2 .command .interaction .button ;
22
3- import org .javacord .api .entity .message . component . ActionRow ;
3+ import org .javacord .api .entity .emoji . Emoji ;
44import org .javacord .api .entity .message .component .Button ;
5+ import org .javacord .api .entity .message .component .ButtonBuilder ;
56import org .javacord .api .entity .message .component .ButtonStyle ;
67
78import java .util .ArrayList ;
@@ -13,6 +14,9 @@ public class ButtonAction {
1314 private final ButtonStyle buttonStyle ;
1415 private Class <? extends ButtonHandler > handler ;
1516 private final List <String > params ;
17+ private boolean disabled = false ;
18+ private String url ;
19+ private Emoji emoji ;
1620
1721 public ButtonAction (String label , ButtonStyle buttonStyle ) {
1822 this .params = new ArrayList <>();
@@ -31,6 +35,21 @@ public ButtonAction addParam(Object param) {
3135 return this ;
3236 }
3337
38+ public ButtonAction setDisabled (boolean disabled ) {
39+ this .disabled = disabled ;
40+ return this ;
41+ }
42+
43+ public ButtonAction setUrl (String url ) {
44+ this .url = url ;
45+ return this ;
46+ }
47+
48+ public ButtonAction setEmoji (Emoji emoji ) {
49+ this .emoji = emoji ;
50+ return this ;
51+ }
52+
3453 public String getCustomId () {
3554 StringBuilder id = new StringBuilder (handler .getName ());
3655 for (String param : params ) {
@@ -47,5 +66,15 @@ public String getCustomId() {
4766
4867 public List <String > getParams () { return params ; }
4968
50- public Button getButton () { return Button .create (getCustomId (), buttonStyle , label ); }
69+ public Button getButton () {
70+ var builder = new ButtonBuilder ()
71+ .setLabel (label )
72+ .setStyle (buttonStyle )
73+ .setDisabled (disabled );
74+ if (buttonStyle != ButtonStyle .LINK ) builder .setCustomId (getCustomId ());
75+ if (url != null && !url .isBlank () && !url .isEmpty () && buttonStyle == ButtonStyle .LINK ) builder .setUrl (url );
76+ if (emoji != null ) builder .setEmoji (emoji );
77+
78+ return builder .build ();
79+ }
5180}
0 commit comments