Skip to content

Commit 569c254

Browse files
committed
feat: better javadoc
1 parent 24effdc commit 569c254

27 files changed

Lines changed: 1665 additions & 25 deletions

src/main/java/fr/traqueur/jdafluent/Choice.java

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,51 +29,136 @@ public String fullLabel() {
2929
return emoji != null ? emoji + " " + label : label;
3030
}
3131

32+
/**
33+
* Create a primary choice with just a label.
34+
*
35+
* @param <T> the type of value
36+
* @param label the display label
37+
* @param value the associated value
38+
* @return a new primary choice
39+
*/
3240
@NotNull
3341
public static <T> Choice<T> of(@NotNull String label, @NotNull T value) {
3442
return new Choice<>(ButtonStyle.PRIMARY, null, label, value);
3543
}
3644

45+
/**
46+
* Create a primary choice with emoji and label.
47+
*
48+
* @param <T> the type of value
49+
* @param emoji the emoji to display
50+
* @param label the display label
51+
* @param value the associated value
52+
* @return a new primary choice with emoji
53+
*/
3754
@NotNull
3855
public static <T> Choice<T> of(@NotNull String emoji, @NotNull String label, @NotNull T value) {
3956
return new Choice<>(ButtonStyle.PRIMARY, emoji, label, value);
4057
}
4158

59+
/**
60+
* Create a primary style choice.
61+
*
62+
* @param <T> the type of value
63+
* @param label the display label
64+
* @param value the associated value
65+
* @return a new primary choice
66+
*/
4267
@NotNull
4368
public static <T> Choice<T> primary(@NotNull String label, @NotNull T value) {
4469
return new Choice<>(ButtonStyle.PRIMARY, null, label, value);
4570
}
4671

72+
/**
73+
* Create a primary style choice with emoji.
74+
*
75+
* @param <T> the type of value
76+
* @param emoji the emoji to display
77+
* @param label the display label
78+
* @param value the associated value
79+
* @return a new primary choice with emoji
80+
*/
4781
@NotNull
4882
public static <T> Choice<T> primary(@NotNull String emoji, @NotNull String label, @NotNull T value) {
4983
return new Choice<>(ButtonStyle.PRIMARY, emoji, label, value);
5084
}
5185

86+
/**
87+
* Create a secondary style choice.
88+
*
89+
* @param <T> the type of value
90+
* @param label the display label
91+
* @param value the associated value
92+
* @return a new secondary choice
93+
*/
5294
@NotNull
5395
public static <T> Choice<T> secondary(@NotNull String label, @NotNull T value) {
5496
return new Choice<>(ButtonStyle.SECONDARY, null, label, value);
5597
}
5698

99+
/**
100+
* Create a secondary style choice with emoji.
101+
*
102+
* @param <T> the type of value
103+
* @param emoji the emoji to display
104+
* @param label the display label
105+
* @param value the associated value
106+
* @return a new secondary choice with emoji
107+
*/
57108
@NotNull
58109
public static <T> Choice<T> secondary(@NotNull String emoji, @NotNull String label, @NotNull T value) {
59110
return new Choice<>(ButtonStyle.SECONDARY, emoji, label, value);
60111
}
61112

113+
/**
114+
* Create a success style choice.
115+
*
116+
* @param <T> the type of value
117+
* @param label the display label
118+
* @param value the associated value
119+
* @return a new success choice
120+
*/
62121
@NotNull
63122
public static <T> Choice<T> success(@NotNull String label, @NotNull T value) {
64123
return new Choice<>(ButtonStyle.SUCCESS, null, label, value);
65124
}
66125

126+
/**
127+
* Create a success style choice with emoji.
128+
*
129+
* @param <T> the type of value
130+
* @param emoji the emoji to display
131+
* @param label the display label
132+
* @param value the associated value
133+
* @return a new success choice with emoji
134+
*/
67135
@NotNull
68136
public static <T> Choice<T> success(@NotNull String emoji, @NotNull String label, @NotNull T value) {
69137
return new Choice<>(ButtonStyle.SUCCESS, emoji, label, value);
70138
}
71139

140+
/**
141+
* Create a danger style choice.
142+
*
143+
* @param <T> the type of value
144+
* @param label the display label
145+
* @param value the associated value
146+
* @return a new danger choice
147+
*/
72148
@NotNull
73149
public static <T> Choice<T> danger(@NotNull String label, @NotNull T value) {
74150
return new Choice<>(ButtonStyle.DANGER, null, label, value);
75151
}
76152

153+
/**
154+
* Create a danger style choice with emoji.
155+
*
156+
* @param <T> the type of value
157+
* @param emoji the emoji to display
158+
* @param label the display label
159+
* @param value the associated value
160+
* @return a new danger choice with emoji
161+
*/
77162
@NotNull
78163
public static <T> Choice<T> danger(@NotNull String emoji, @NotNull String label, @NotNull T value) {
79164
return new Choice<>(ButtonStyle.DANGER, emoji, label, value);

src/main/java/fr/traqueur/jdafluent/JDAFluent.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ public class JDAFluent {
6666
private final Selects selects;
6767
private final Awaiters awaiters;
6868

69+
/**
70+
* Create a new JDAFluent instance.
71+
*
72+
* @param jda the JDA instance to use
73+
*/
6974
public JDAFluent(@NotNull JDA jda) {
7075
this.jda = jda;
7176
this.buttons = new Buttons();
@@ -81,6 +86,8 @@ public JDAFluent(@NotNull JDA jda) {
8186

8287
/**
8388
* Get the JDA instance.
89+
*
90+
* @return the JDA instance
8491
*/
8592
@NotNull
8693
public JDA jda() {
@@ -89,6 +96,8 @@ public JDA jda() {
8996

9097
/**
9198
* Get the buttons registry for low-level button management.
99+
*
100+
* @return the Buttons instance
92101
*/
93102
@NotNull
94103
public Buttons buttons() {
@@ -97,6 +106,8 @@ public Buttons buttons() {
97106

98107
/**
99108
* Get the dialogs factory for ephemeral interactions.
109+
*
110+
* @return the Dialogs instance
100111
*/
101112
@NotNull
102113
public Dialogs dialogs() {
@@ -105,6 +116,8 @@ public Dialogs dialogs() {
105116

106117
/**
107118
* Get the panels factory for permanent interactions.
119+
*
120+
* @return the Panels instance
108121
*/
109122
@NotNull
110123
public Panels panels() {
@@ -113,6 +126,8 @@ public Panels panels() {
113126

114127
/**
115128
* Get the modals factory for modal dialogs.
129+
*
130+
* @return the Modals instance
116131
*/
117132
@NotNull
118133
public Modals modals() {
@@ -121,6 +136,8 @@ public Modals modals() {
121136

122137
/**
123138
* Get the selects factory for select menus.
139+
*
140+
* @return the Selects instance
124141
*/
125142
@NotNull
126143
public Selects selects() {
@@ -129,6 +146,8 @@ public Selects selects() {
129146

130147
/**
131148
* Get the awaiters factory for waiting on events.
149+
*
150+
* @return the Awaiters instance
132151
*/
133152
@NotNull
134153
public Awaiters awaiters() {
@@ -137,6 +156,8 @@ public Awaiters awaiters() {
137156

138157
/**
139158
* Get a combined listener for all interactions.
159+
*
160+
* @return a ListenerAdapter that handles all interaction events
140161
*/
141162
@NotNull
142163
public ListenerAdapter asListener() {

src/main/java/fr/traqueur/jdafluent/awaiters/Awaiter.java

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,55 @@
2222
*/
2323
public abstract class Awaiter<E extends GenericEvent, R, S extends Awaiter<E, R, S>> {
2424

25+
/**
26+
* The awaiters factory containing JDA and scheduler.
27+
*/
2528
protected final Awaiters awaiters;
2629

30+
/**
31+
* The user to filter events from, or null for any user.
32+
*/
2733
protected User fromUser;
34+
35+
/**
36+
* The channel to filter events in, or null for any channel.
37+
*/
2838
protected MessageChannel inChannel;
39+
40+
/**
41+
* The timeout duration before the awaiter expires.
42+
*/
2943
protected Duration timeout = Duration.ofMinutes(1);
44+
45+
/**
46+
* Additional filter predicate for results.
47+
*/
3048
protected Predicate<R> filter = r -> true;
49+
50+
/**
51+
* Handler called when a matching event is received.
52+
*/
3153
protected Consumer<R> onResponse;
54+
55+
/**
56+
* Handler called when the timeout is reached.
57+
*/
3258
protected Runnable onTimeout;
3359

60+
/**
61+
* Creates a new awaiter.
62+
*
63+
* @param awaiters the awaiters factory
64+
*/
3465
protected Awaiter(@NotNull Awaiters awaiters) {
3566
this.awaiters = awaiters;
3667
}
3768

3869
/**
3970
* Only accept events from this user.
71+
*
72+
* @param user the user to filter events from
73+
* @return this awaiter for chaining
4074
*/
4175
@NotNull
4276
public S from(@NotNull User user) {
@@ -46,6 +80,9 @@ public S from(@NotNull User user) {
4680

4781
/**
4882
* Only accept events in this channel.
83+
*
84+
* @param channel the channel to filter events in
85+
* @return this awaiter for chaining
4986
*/
5087
@NotNull
5188
public S inChannel(@NotNull MessageChannel channel) {
@@ -55,6 +92,9 @@ public S inChannel(@NotNull MessageChannel channel) {
5592

5693
/**
5794
* Set the timeout duration.
95+
*
96+
* @param timeout the timeout duration
97+
* @return this awaiter for chaining
5898
*/
5999
@NotNull
60100
public S timeout(@NotNull Duration timeout) {
@@ -64,6 +104,9 @@ public S timeout(@NotNull Duration timeout) {
64104

65105
/**
66106
* Additional filter for results.
107+
*
108+
* @param filter the filter predicate to apply
109+
* @return this awaiter for chaining
67110
*/
68111
@NotNull
69112
public S filter(@NotNull Predicate<R> filter) {
@@ -73,6 +116,9 @@ public S filter(@NotNull Predicate<R> filter) {
73116

74117
/**
75118
* Handler when a matching event is received.
119+
*
120+
* @param handler the handler to call with the result
121+
* @return this awaiter for chaining
76122
*/
77123
@NotNull
78124
public S onResponse(@NotNull Consumer<R> handler) {
@@ -82,6 +128,9 @@ public S onResponse(@NotNull Consumer<R> handler) {
82128

83129
/**
84130
* Handler when timeout is reached.
131+
*
132+
* @param handler the handler to call on timeout
133+
* @return this awaiter for chaining
85134
*/
86135
@NotNull
87136
public S onTimeout(@NotNull Runnable handler) {
@@ -113,36 +162,52 @@ public void start() {
113162

114163
/**
115164
* Return this as the self type for fluent chaining.
165+
*
166+
* @return this awaiter cast to the self type
116167
*/
117168
@NotNull
118169
protected abstract S self();
119170

120171
/**
121172
* Get the event class to listen for.
173+
*
174+
* @return the event class
122175
*/
123176
@NotNull
124177
protected abstract Class<E> getEventClass();
125178

126179
/**
127180
* Extract the user from the event (for filtering).
181+
*
182+
* @param event the event to extract from
183+
* @return the user, or null if not applicable
128184
*/
129185
@Nullable
130186
protected abstract User extractUser(@NotNull E event);
131187

132188
/**
133189
* Extract the channel from the event (for filtering).
190+
*
191+
* @param event the event to extract from
192+
* @return the channel, or null if not applicable
134193
*/
135194
@Nullable
136195
protected abstract MessageChannel extractChannel(@NotNull E event);
137196

138197
/**
139198
* Extract the result from the event.
199+
*
200+
* @param event the event to extract from
201+
* @return the extracted result
140202
*/
141203
@NotNull
142204
protected abstract R extractResult(@NotNull E event);
143205

144206
/**
145207
* Check if the event should be ignored (e.g., bot messages).
208+
*
209+
* @param event the event to check
210+
* @return true if the event should be ignored
146211
*/
147212
protected boolean shouldIgnore(@NotNull E event) {
148213
return false;
@@ -151,6 +216,8 @@ protected boolean shouldIgnore(@NotNull E event) {
151216
/**
152217
* Called after a successful match, before the handler.
153218
* Can be used for cleanup like deleting messages.
219+
*
220+
* @param event the matched event
154221
*/
155222
protected void onMatch(@NotNull E event) {
156223
// Default: do nothing

0 commit comments

Comments
 (0)