Fixes quotation marks in titles on /transfer#1332
Fixes quotation marks in titles on /transfer#1332Bobi222 wants to merge 2 commits intoTogether-Java:developfrom
Conversation
|
|
||
| String generateTitle(String originalMessage) { | ||
| String chatGptTitleRequest = | ||
| "Summarize the following question into a concise title or heading not more than 5 words, remove quotations if any: %s" | ||
| .formatted(originalMessage); | ||
| Optional<String> chatGptTitle = chatGptService.ask(chatGptTitleRequest, null); | ||
| String title = chatGptTitle.orElse(createTitle(originalMessage)); | ||
|
|
||
| // 🔧 FIX: Remove surrounding quotes | ||
| title = title.replaceAll("^\"|\"$", ""); | ||
|
|
||
| if (title.length() > TITLE_MAX_LENGTH) { | ||
| title = title.substring(0, TITLE_MAX_LENGTH); | ||
| } | ||
|
|
||
| return title; | ||
| } | ||
|
|
||
|
|
There was a problem hiding this comment.
is this a leftover or something? that new method isnt used anywhere. remove it or use it
There was a problem hiding this comment.
Hi, yes my bad i will find a cleaner fix. Pardon my mistakes im new to contributing
| .formatted(originalMessage); | ||
| Optional<String> chatGptTitle = chatGptService.ask(chatGptTitleRequest, null); | ||
| String title = chatGptTitle.orElse(createTitle(originalMessage)); | ||
| title = title.replaceAll("^[\"']|[\"']$", ""); |
There was a problem hiding this comment.
please chain it instead.
| title = title.replaceAll("^[\"']|[\"']$", ""); | |
| String title = chatGptTitle.orElse(createTitle(originalMessage)) | |
| .replaceAll("^[\"']|[\"']$", ""); |
There was a problem hiding this comment.
Im not a fan of your regex for two reasons:
- currently it also triggers when just one condition is met, for example
Need help with "foo"or"Foo" is weird, it shouldnt trigger here. Only for"Foo bar". - if we do the first part then regex is overkill for this
so i propose to instead add if (title.startsWith("\"") && title.endsWith("\"")) { title = title.substring(1, title.length() - 1); } or something like that.
that said, i dont have a strong opinion on avoiding regex here specifically, so whatever. but please fix the first part.
There was a problem hiding this comment.
Ok im on it. Thanks for the guidance.
| event.getGuild()) | ||
| .and(sendMessageToTransferrer.apply(createdForumPost))) | ||
| event.getGuild()).and(sendMessageToTransferrer.apply(createdForumPost))) |
There was a problem hiding this comment.
you didnt change anything here. i wouldnt be surprised if this will be auto-reverted the second you run spotless
Added a regex to remove the quotation marks in the begging and in the end of the title (single or double).
Fixes and closes #1134