Skip to content

Commit 385820d

Browse files
committed
Fix checkstyle
1 parent 7fccf8e commit 385820d

File tree

3 files changed

+64
-5
lines changed

3 files changed

+64
-5
lines changed

src/main/java/net/discordjug/javabot/systems/staff_commands/forms/model/FormData.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,26 @@
1212

1313
/**
1414
* Class containing information about a form.
15+
*
16+
* @param id the form ID.
17+
* @param fields a list of text input fields associated with this form.
18+
* A form can only hold a maximum of 5 fields at a time.
19+
* @param title form title used in the modal displayed to the user.
20+
* @param submitChannel ID of the channel the form submissions are sent to.
21+
* @param submitMessage message displayed to the user once they submit the
22+
* form.
23+
* @param messageId ID of the message this form is attached to. null if the
24+
* form is not attached to any message.
25+
* @param messageChannel channel of the message this form is attached to. null
26+
* if the form is not attached to any message.
27+
* @param expiration time after which this user won't accept any further
28+
* submissions. null to indicate that the form has no
29+
* expiration date.
30+
* @param closed closed state of this form. If the form is closed, it
31+
* doesn't accept further submissions, even if it's
32+
* expired.
33+
* @param onetime onetime state of this form. If it's true, the form only
34+
* accepts one submission per user.
1535
*/
1636
// TODO `Optional` getter for the submit message
1737
public record FormData(long id, List<FormField> fields, String title, long submitChannel, String submitMessage,
@@ -23,9 +43,15 @@ public record FormData(long id, List<FormField> fields, String title, long submi
2343
*/
2444
public static final long EXPIRATION_PERMANENT = -1;
2545

46+
/**
47+
* The main constructor.
48+
*/
2649
public FormData {
2750
Objects.requireNonNull(title);
2851
fields = List.copyOf(fields);
52+
if (fields.size() > 5) {
53+
throw new IllegalArgumentException("fields.size() > 5");
54+
}
2955
}
3056

3157
public boolean isAttached() {

src/main/java/net/discordjug/javabot/systems/staff_commands/forms/model/FormField.java

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,45 @@
11
package net.discordjug.javabot.systems.staff_commands.forms.model;
22

3+
import java.util.Objects;
4+
35
import net.dv8tion.jda.api.interactions.components.text.TextInput;
46
import net.dv8tion.jda.api.interactions.components.text.TextInputStyle;
57

68
/**
7-
* Represents a form field.
8-
* Form fields are used to store data about text inputs presented to the user in the form modal.
9-
* Each form can have up to 5 fields.
9+
* Represents a form field. Form fields are used to store data about text inputs
10+
* presented to the user in the form modal. Each form can have up to 5 fields.
11+
*
12+
* @param label field label.
13+
* @param max maximum number of characters allowed to be entered in this
14+
* field.
15+
* @param min minimum number of characters required. Setting min to a
16+
* value greater than 0 will make this field effectively
17+
* required, even if the {@code required} parameter is set to
18+
* false.
19+
* @param placeholder field placeholder. Use null to use any placeholder.
20+
* @param required whether or not the user has to type something in this
21+
* field.
22+
* @param style text input style.
23+
* @param value initial field value. Can be null to indicate no inital
24+
* value.
25+
* @param id form id.
1026
*/
11-
public record FormField(String label, int max, int min, String placeholder, boolean required,
12-
TextInputStyle style, String value, long id) {
27+
public record FormField(String label, int max, int min, String placeholder, boolean required, TextInputStyle style,
28+
String value, long id) {
29+
30+
/**
31+
* The main constructor.
32+
*/
33+
public FormField {
34+
Objects.requireNonNull(label);
35+
if (min < 0) throw new IllegalArgumentException("min < 0");
36+
37+
if (max < 1) throw new IllegalArgumentException("max < 1");
38+
39+
if (max < min) throw new IllegalArgumentException("max < min");
40+
41+
Objects.requireNonNull(style);
42+
}
1343

1444
/**
1545
* Create a text input from this field.

src/main/java/net/discordjug/javabot/systems/staff_commands/forms/model/FormUser.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
/**
44
* Represents a user who submitted a form.
5+
*
6+
* @param id user's ID.
7+
* @param username user's Discord username.
58
*/
69
public record FormUser(long id, String username) {
710

0 commit comments

Comments
 (0)