@@ -35,18 +35,20 @@ public class AutoCodeFormatter {
3535 /**
3636 * Method responsible for finding a place to insert a codeblock, if present.
3737 *
38- * @param event a {@link MessageReceivedEvent} .
38+ * @param msg the content of the message .
3939 * @return a MessageCodeblock instance, holding a startIndex, content and
4040 * an endIndex. Returns null if no place was found.
4141 */
4242 @ Nullable
43- private static CodeBlock findCodeblock (@ NotNull MessageReceivedEvent event ) {
44- String msg = event .getMessage ().getContentRaw ();
43+ private static CodeBlock findCodeblock (@ NotNull String msg ) {
4544 int openingBracket = msg .indexOf ("{" );
4645 int closingBracket = msg .lastIndexOf ("}" );
4746 if (closingBracket == -1 || openingBracket == -1 ) {
4847 return null ;
4948 }
49+ if (!msg .substring (openingBracket , closingBracket ).contains ("\n " )) {
50+ return null ;
51+ }
5052 int startIndex = msg .lastIndexOf ("\n " , openingBracket );
5153 int endIndex = msg .indexOf ("\n " , closingBracket );
5254 if (startIndex == -1 ) {
@@ -99,11 +101,11 @@ void handleMessageEvent(@Nonnull MessageReceivedEvent event, boolean isFirstMess
99101 }
100102
101103
102- if (event .getMessage ().getContentRaw ().contains ("``` " )) {
104+ if (event .getMessage ().getContentRaw ().contains ("`" )) {
103105 return ; // exit if already contains codeblock
104106 }
105107
106- CodeBlock code = findCodeblock (event );
108+ CodeBlock code = findCodeblock (event . getMessage (). getContentRaw () );
107109 if (code == null ) {
108110 return ;
109111 }
0 commit comments