Skip to content

Commit ed1c7bb

Browse files
committed
create constants for codeblock prefix and suffix
1 parent a9006c3 commit ed1c7bb

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/main/java/net/discordjug/javabot/systems/help/AutoCodeFormatter.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
@RequiredArgsConstructor
2929
@Component
3030
public class AutoCodeFormatter {
31+
private static final String CODEBLOCK_PREFIX = " ```java";
32+
private static final String CODEBLOCK_SUFFIX = " ```";
3133
private final AutoMod autoMod;
3234
private final BotConfig botConfig;
3335
private final UserPreferenceService preferenceService;
@@ -129,15 +131,16 @@ private void sendFormatHint(MessageReceivedEvent event) {
129131
).queue();
130132
}
131133

134+
132135
private void replaceUnformattedCode(String msg, int codeStartIndex, int codeEndIndex, MessageReceivedEvent event) {
133136
// default case: a "normal", non-ping containing, non first message of a forum-thread containing "{" and "}".
134137
// user must also have set their preferences to allow this.
135-
if (msg.length() > Message.MAX_CONTENT_LENGTH - 12) { // can't exceed discord's char limit
138+
if (msg.length() > Message.MAX_CONTENT_LENGTH - CODEBLOCK_PREFIX.length() - CODEBLOCK_SUFFIX.length()) { // can't exceed discord's char limit
136139
sendFormatHint(event);
137140
return;
138141
}
139-
String messageContent = msg.substring(0, codeStartIndex) + " ```java" +
140-
msg.substring(codeStartIndex, codeEndIndex) + " ```" + msg.substring(codeEndIndex);
142+
String messageContent = msg.substring(0, codeStartIndex) + CODEBLOCK_PREFIX +
143+
msg.substring(codeStartIndex, codeEndIndex) + CODEBLOCK_SUFFIX + msg.substring(codeEndIndex);
141144
EmbedBuilder autoformatInfo = new EmbedBuilder().setDescription(botConfig.get(event.getGuild())
142145
.getHelpConfig()
143146
.getAutoFormatInfoMessage());

0 commit comments

Comments
 (0)