Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.dv8tion.jda.api.interactions.commands.build.Commands;
import net.dv8tion.jda.api.interactions.components.Modal;
import net.dv8tion.jda.api.interactions.components.text.TextInput;
import net.dv8tion.jda.api.interactions.components.text.TextInput.Builder;
import net.dv8tion.jda.api.interactions.components.text.TextInputStyle;
import net.dv8tion.jda.api.requests.RestAction;
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
Expand Down Expand Up @@ -89,12 +90,14 @@ public void onMessageContext(MessageContextInteractionEvent event) {
.setValue(createTitle(originalMessage))
.build();

TextInput modalInput =
Builder modalInputBuilder =
TextInput.create(MODAL_INPUT_ID, "Question", TextInputStyle.PARAGRAPH)
.setValue(originalMessage)
.setRequiredRange(INPUT_MIN_LENGTH, INPUT_MAX_LENGTH)
.setPlaceholder("Contents of the question")
.build();
.setPlaceholder("Contents of the question");

if (!isQuestionTooShort(originalMessage)) {
modalInputBuilder.setValue(originalMessage);
}

TextInput modalTag = TextInput.create(MODAL_TAG, "Most fitting tag", TextInputStyle.SHORT)
.setValue(mostCommonTag)
Expand All @@ -105,7 +108,7 @@ public void onMessageContext(MessageContextInteractionEvent event) {
generateComponentId(authorId, originalMessageId, originalChannelId);
Modal transferModal = Modal.create(modalComponentId, "Transfer this question")
.addActionRow(modalTitle)
.addActionRow(modalInput)
.addActionRow(modalInputBuilder.build())
.addActionRow(modalTag)
.build();

Expand Down Expand Up @@ -242,26 +245,13 @@ private boolean isQuestionTooShort(String question) {
return question.length() < INPUT_MIN_LENGTH;
}

private void handleQuestionTooShort(MessageContextInteractionEvent event) {
event
.reply("Message content should be at least %s characters long."
.formatted(INPUT_MIN_LENGTH))
.setEphemeral(true)
.queue();
}

private boolean isInvalidForTransfer(MessageContextInteractionEvent event) {
String question = event.getTarget().getContentRaw();
User author = event.getTarget().getAuthor();

if (isBotMessageTransfer(author)) {
handleBotMessageTransfer(event);
return true;
}
if (isQuestionTooShort(question)) {
handleQuestionTooShort(event);
return true;
}
return false;
}
}