Skip to content
Merged
Changes from all 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 @@ -10,6 +10,7 @@
import net.discordjug.javabot.util.WebhookUtil;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;

Expand All @@ -27,6 +28,8 @@
@RequiredArgsConstructor
@Component
public class AutoCodeFormatter {
private static final String CODEBLOCK_PREFIX = " ```java";
private static final String CODEBLOCK_SUFFIX = " ```";
private final AutoMod autoMod;
private final BotConfig botConfig;
private final UserPreferenceService preferenceService;
Expand Down Expand Up @@ -128,15 +131,16 @@ private void sendFormatHint(MessageReceivedEvent event) {
).queue();
}


private void replaceUnformattedCode(String msg, int codeStartIndex, int codeEndIndex, MessageReceivedEvent event) {
// default case: a "normal", non-ping containing, non first message of a forum-thread containing "{" and "}".
// user must also have set their preferences to allow this.
if (msg.length() > 1992) { // can't exceed discord's char limit
if (msg.length() > Message.MAX_CONTENT_LENGTH - CODEBLOCK_PREFIX.length() - CODEBLOCK_SUFFIX.length()) { // can't exceed discord's char limit
sendFormatHint(event);
return;
}
String messageContent = msg.substring(0, codeStartIndex) + " ```" +
msg.substring(codeStartIndex, codeEndIndex) + " ```" + msg.substring(codeEndIndex);
String messageContent = msg.substring(0, codeStartIndex) + CODEBLOCK_PREFIX +
msg.substring(codeStartIndex, codeEndIndex) + CODEBLOCK_SUFFIX + msg.substring(codeEndIndex);
EmbedBuilder autoformatInfo = new EmbedBuilder().setDescription(botConfig.get(event.getGuild())
.getHelpConfig()
.getAutoFormatInfoMessage());
Expand Down