1515import net .dv8tion .jda .api .interactions .commands .build .Commands ;
1616import net .dv8tion .jda .api .interactions .components .Modal ;
1717import net .dv8tion .jda .api .interactions .components .text .TextInput ;
18+ import net .dv8tion .jda .api .interactions .components .text .TextInput .Builder ;
1819import net .dv8tion .jda .api .interactions .components .text .TextInputStyle ;
1920import net .dv8tion .jda .api .requests .RestAction ;
2021import net .dv8tion .jda .api .utils .messages .MessageCreateBuilder ;
@@ -49,6 +50,8 @@ public final class TransferQuestionCommand extends BotCommandAdapter
4950 private static final Pattern TITLE_GUESS_COMPACT_REMOVAL_PATTERN = Pattern .compile ("\\ W" );
5051 private static final int TITLE_MIN_LENGTH = 3 ;
5152 private static final Color EMBED_COLOR = new Color (50 , 164 , 168 );
53+ private static final int INPUT_MAX_LENGTH = Message .MAX_CONTENT_LENGTH ;
54+ private static final int INPUT_MIN_LENGTH = 3 ;
5255 private final Predicate <String > isHelpForumName ;
5356 private final List <String > tags ;
5457
@@ -70,7 +73,7 @@ public TransferQuestionCommand(Config config) {
7073 @ Override
7174 public void onMessageContext (MessageContextInteractionEvent event ) {
7275
73- if (isBotMessageTransfer (event )) {
76+ if (isInvalidForTransfer (event )) {
7477 return ;
7578 }
7679
@@ -87,12 +90,15 @@ public void onMessageContext(MessageContextInteractionEvent event) {
8790 .setValue (createTitle (originalMessage ))
8891 .build ();
8992
90- TextInput modalInput =
93+ Builder modalInputBuilder =
9194 TextInput .create (MODAL_INPUT_ID , "Question" , TextInputStyle .PARAGRAPH )
92- .setValue (originalMessage )
93- .setRequiredRange (3 , 2000 )
94- .setPlaceholder ("Contents of the question" )
95- .build ();
95+ .setRequiredRange (INPUT_MIN_LENGTH , INPUT_MAX_LENGTH )
96+ .setPlaceholder ("Contents of the question" );
97+
98+ if (!isQuestionTooShort (originalMessage )) {
99+ String trimmedMessage = getMessageUptoMaxLimit (originalMessage );
100+ modalInputBuilder .setValue (trimmedMessage );
101+ }
96102
97103 TextInput modalTag = TextInput .create (MODAL_TAG , "Most fitting tag" , TextInputStyle .SHORT )
98104 .setValue (mostCommonTag )
@@ -103,7 +109,7 @@ public void onMessageContext(MessageContextInteractionEvent event) {
103109 generateComponentId (authorId , originalMessageId , originalChannelId );
104110 Modal transferModal = Modal .create (modalComponentId , "Transfer this question" )
105111 .addActionRow (modalTitle )
106- .addActionRow (modalInput )
112+ .addActionRow (modalInputBuilder . build () )
107113 .addActionRow (modalTag )
108114 .build ();
109115
@@ -228,11 +234,31 @@ private MessageEmbed makeEmbedForPost(User originalUser, String originalMessage)
228234 private record ForumPost (User author , Message message ) {
229235 }
230236
231- private boolean isBotMessageTransfer (MessageContextInteractionEvent event ) {
232- if (event .getTarget ().getAuthor ().isBot ()) {
233- event .reply ("Cannot transfer messages from a bot." ).setEphemeral (true ).queue ();
237+ private boolean isBotMessageTransfer (User author ) {
238+ return author .isBot ();
239+ }
240+
241+ private void handleBotMessageTransfer (MessageContextInteractionEvent event ) {
242+ event .reply ("Cannot transfer messages from a bot." ).setEphemeral (true ).queue ();
243+ }
244+
245+ private boolean isQuestionTooShort (String question ) {
246+ return question .length () < INPUT_MIN_LENGTH ;
247+ }
248+
249+ private boolean isInvalidForTransfer (MessageContextInteractionEvent event ) {
250+ User author = event .getTarget ().getAuthor ();
251+
252+ if (isBotMessageTransfer (author )) {
253+ handleBotMessageTransfer (event );
234254 return true ;
235255 }
236256 return false ;
237257 }
258+
259+ private String getMessageUptoMaxLimit (String originalMessage ) {
260+ return originalMessage .length () > INPUT_MAX_LENGTH
261+ ? originalMessage .substring (0 , INPUT_MAX_LENGTH )
262+ : originalMessage ;
263+ }
238264}
0 commit comments