Skip to content

Commit 40728f5

Browse files
committed
Resolve TODO comments in forms feature classes
1 parent cc20300 commit 40728f5

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

src/main/java/net/discordjug/javabot/systems/staff_commands/forms/FormInteractionManager.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.util.Optional;
1111
import java.util.TimeZone;
1212
import java.util.function.Function;
13+
1314
import lombok.RequiredArgsConstructor;
1415
import net.discordjug.javabot.annotations.AutoDetectableComponentHandler;
1516
import net.discordjug.javabot.systems.staff_commands.forms.dao.FormsRepository;
@@ -155,9 +156,7 @@ public void handleModal(ModalInteractionEvent event, List<ModalMapping> values)
155156
formsRepo.addSubmission(event.getUser(), form, msg);
156157
});
157158

158-
event.getHook()
159-
.sendMessage(form.submitMessage() == null ? "Your submission was received!" : form.submitMessage())
160-
.queue();
159+
event.getHook().sendMessage(form.getOptionalSubmitMessage().orElse("Your submission was received!")).queue();
161160
}
162161

163162
/**

src/main/java/net/discordjug/javabot/systems/staff_commands/forms/commands/DetailsFormSubcommand.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ private EmbedBuilder createFormDetailsEmbed(FormData form, Guild guild) {
111111

112112
builder.addField("Submissions channel", submissionsChannelMention, true);
113113
builder.addField("Is one-time", form.onetime() ? ":white_check_mark:" : ":x:", true);
114-
addCodeblockField(builder, "Submission message",
115-
form.submitMessage() == null ? "Default" : form.submitMessage(), true);
114+
addCodeblockField(builder, "Submission message", form.getOptionalSubmitMessage().orElse("Default"), true);
116115

117116
addCodeblockField(builder, "Number of fields", form.fields().size(), true);
118117
addCodeblockField(builder, "Number of submissions", formsRepo.getTotalSubmissionsCount(form), true);

src/main/java/net/discordjug/javabot/systems/staff_commands/forms/commands/FormCommand.java

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

3+
import net.dv8tion.jda.api.interactions.InteractionContextType;
34
import net.dv8tion.jda.api.interactions.commands.DefaultMemberPermissions;
45
import net.dv8tion.jda.api.interactions.commands.build.Commands;
56
import xyz.dynxsty.dih4jda.interactions.commands.application.SlashCommand;
@@ -34,8 +35,7 @@ public FormCommand(CreateFormSubcommand createSub, DeleteFormSubcommand deleteSu
3435
AttachFormSubcommand attachSub, DetachFormSubcommand detachSub,
3536
SubmissionsExportFormSubcommand submissionsGetSub, SubmissionsDeleteFormSubcommand submissionsDeleteSub) {
3637
setCommandData(Commands.slash("form", "Commands for managing modal forms")
37-
.setDefaultPermissions(DefaultMemberPermissions.DISABLED)); // TODO check for an option to make the
38-
// command guild only
38+
.setContexts(InteractionContextType.GUILD).setDefaultPermissions(DefaultMemberPermissions.DISABLED));
3939
addSubcommands(createSub, deleteSub, closeSub, reopenSub, detailsSub, modifySub, addFieldSub, removeFieldSub,
4040
showSub, attachSub, detachSub, submissionsGetSub, submissionsDeleteSub);
4141
}

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.List;
88
import java.util.Objects;
99
import java.util.Optional;
10+
1011
import net.discordjug.javabot.systems.staff_commands.forms.FormInteractionManager;
1112
import net.dv8tion.jda.api.components.label.Label;
1213

@@ -33,7 +34,6 @@
3334
* @param onetime onetime state of this form. If it's true, the form only
3435
* accepts one submission per user.
3536
*/
36-
// TODO `Optional` getter for the submit message
3737
public record FormData(long id, List<FormField> fields, String title, long submitChannel, String submitMessage,
3838
Long messageId, Long messageChannel, Instant expiration, boolean closed, boolean onetime) {
3939

@@ -48,6 +48,19 @@ public record FormData(long id, List<FormField> fields, String title, long submi
4848
}
4949
}
5050

51+
/**
52+
* Get this form's submit message as an {@link Optional}. If the message is null
53+
* or blank, the returned optional will be empty.
54+
*
55+
* @return optional submit message
56+
*/
57+
public Optional<String> getOptionalSubmitMessage() {
58+
if (submitMessage == null || submitMessage.isBlank()) {
59+
return Optional.empty();
60+
}
61+
return Optional.of(submitMessage);
62+
}
63+
5164
/**
5265
* Get information about the form's attachment state. If the form is attached to
5366
* a message, this method will return a non-empty optional containin information
@@ -106,7 +119,6 @@ public String toString() {
106119
} else if (hasExpired()) {
107120
prefix = "Expired";
108121
} else {
109-
// TODO change how date and time is formatted
110122
prefix = FormInteractionManager.DATE_FORMAT.format(new Date(expiration.toEpochMilli())) + " UTC";
111123
}
112124

0 commit comments

Comments
 (0)