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 @@ -35,18 +35,20 @@ public class AutoCodeFormatter {
/**
* Method responsible for finding a place to insert a codeblock, if present.
*
* @param event a {@link MessageReceivedEvent}.
* @param msg the content of the message.
* @return a MessageCodeblock instance, holding a startIndex, content and
* an endIndex. Returns null if no place was found.
*/
@Nullable
private static CodeBlock findCodeblock(@NotNull MessageReceivedEvent event) {
String msg = event.getMessage().getContentRaw();
private static CodeBlock findCodeblock(@NotNull String msg) {
int openingBracket = msg.indexOf("{");
int closingBracket = msg.lastIndexOf("}");
if (closingBracket == -1 || openingBracket == -1) {
return null;
}
if (!msg.substring(openingBracket, closingBracket).contains("\n")) {
return null;
}
int startIndex = msg.lastIndexOf("\n", openingBracket);
int endIndex = msg.indexOf("\n", closingBracket);
if (startIndex == -1) {
Expand Down Expand Up @@ -99,11 +101,11 @@ void handleMessageEvent(@Nonnull MessageReceivedEvent event, boolean isFirstMess
}


if (event.getMessage().getContentRaw().contains("```")) {
if (event.getMessage().getContentRaw().contains("`")) {
return; // exit if already contains codeblock
}

CodeBlock code = findCodeblock(event);
CodeBlock code = findCodeblock(event.getMessage().getContentRaw());
if (code == null) {
return;
}
Expand Down