@@ -100,6 +100,11 @@ public void onMessageContext(MessageContextInteractionEvent event) {
100100 .formatted (originalMessage );
101101 Optional <String > chatGptTitle = chatGptService .ask (chatGptTitleRequest , null );
102102 String title = chatGptTitle .orElse (createTitle (originalMessage ));
103+
104+ // Fix
105+ title = title .replaceAll ("^[\" ']|[\" ']$" , "" );
106+ //
107+
103108 if (title .length () > TITLE_MAX_LENGTH ) {
104109 title = title .substring (0 , TITLE_MAX_LENGTH );
105110 }
@@ -137,6 +142,25 @@ public void onMessageContext(MessageContextInteractionEvent event) {
137142 event .replyModal (transferModal ).queue ();
138143 }
139144
145+
146+ String generateTitle (String originalMessage ) {
147+ String chatGptTitleRequest =
148+ "Summarize the following question into a concise title or heading not more than 5 words, remove quotations if any: %s"
149+ .formatted (originalMessage );
150+ Optional <String > chatGptTitle = chatGptService .ask (chatGptTitleRequest , null );
151+ String title = chatGptTitle .orElse (createTitle (originalMessage ));
152+
153+ // 🔧 FIX: Remove surrounding quotes
154+ title = title .replaceAll ("^\" |\" $" , "" );
155+
156+ if (title .length () > TITLE_MAX_LENGTH ) {
157+ title = title .substring (0 , TITLE_MAX_LENGTH );
158+ }
159+
160+ return title ;
161+ }
162+
163+
140164 @ Override
141165 public void onModalSubmitted (ModalInteractionEvent event , List <String > args ) {
142166 event .deferReply (true ).queue ();
@@ -175,8 +199,7 @@ private void transferFlow(ModalInteractionEvent event, String channelId, String
175199 .retrieveUserById (authorId )
176200 .flatMap (fetchedUser -> createForumPost (event , fetchedUser ))
177201 .flatMap (createdForumPost -> dmUser (event .getChannel (), createdForumPost ,
178- event .getGuild ())
179- .and (sendMessageToTransferrer .apply (createdForumPost )))
202+ event .getGuild ()).and (sendMessageToTransferrer .apply (createdForumPost )))
180203 .flatMap (dmSent -> deleteOriginalMessage (event .getJDA (), channelId , messageId ))
181204 .queue ();
182205 }
0 commit comments