From 7a88542664b261ef7ac92a5644e8f90c7acf8d90 Mon Sep 17 00:00:00 2001 From: Dan Shernicoff Date: Wed, 24 Jun 2026 16:36:06 -0400 Subject: [PATCH 1/5] Fix issue with apparent codeblock within other codeblock If there is a triple quoted string inside a codeblock that that appears invalid the current implementation will trigger the the "Bat ticks message". This is confusing to the user and generally wrong because that happens to be correct. What needs to happen is that the we should isolate the codeblocks and make sure that the violating codeblock is not contained within a codeblock. This change handles that scenario by checking all of the invalid codeblocks to generate the correct message based on the invalid codeblock. If a message contains multiple invalid codeblocks and there is at least one that is using invalid ticks the invalid ticks message will be shown. If there is no codeblock with invalid ticks the missing language and no language logic will be followed without change. --- bot/exts/info/codeblock/_instructions.py | 31 ++++++++++++++++-------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/bot/exts/info/codeblock/_instructions.py b/bot/exts/info/codeblock/_instructions.py index 7204dbeae4..ae81ceaca7 100644 --- a/bot/exts/info/codeblock/_instructions.py +++ b/bot/exts/info/codeblock/_instructions.py @@ -1,17 +1,13 @@ """This module generates and formats instructional messages about fixing Markdown code blocks.""" - from bot.exts.info.codeblock import _parsing from bot.log import get_logger log = get_logger(__name__) -_EXAMPLE_PY = "{lang}\nprint('Hello, world!')" # Make sure to escape any Markdown symbols here. -_EXAMPLE_CODE_BLOCKS = ( - "\\`\\`\\`{content}\n\\`\\`\\`\n\n" - "**This will result in the following:**\n" - "```{content}```" -) +# Make sure to escape any Markdown symbols here. +_EXAMPLE_PY = "{lang}\nprint('Hello, world!')" +_EXAMPLE_CODE_BLOCKS = "\\`\\`\\`{content}\n\\`\\`\\`\n\n**This will result in the following:**\n```{content}```" def _get_example(language: str) -> str: @@ -37,8 +33,7 @@ def _get_bad_ticks_message(code_block: _parsing.CodeBlock) -> str | None: valid_ticks = f"\\{_parsing.BACKTICK}" * 3 instructions = ( - "You are using the wrong character instead of backticks. " - f"Use {valid_ticks}, not `{code_block.ticks}`." + f"You are using the wrong character instead of backticks. Use {valid_ticks}, not `{code_block.ticks}`." ) log.trace("Check if the bad ticks code block also has issues with the language specifier.") @@ -148,7 +143,23 @@ def get_instructions(content: str) -> str | None: instructions = _get_no_ticks_message(content) else: log.trace("Searching results for a code block with invalid ticks.") - block = next((block for block in blocks if block.tick != _parsing.BACKTICK), None) + bad_ticks = [block for block in blocks if block.tick != _parsing.BACKTICK] + block = None + if bad_ticks: + block = next( + ( + bad_tick + for bad_tick in bad_ticks + if any( + block + for block in blocks + if block != bad_tick + and bad_tick.content != block.content + and bad_tick.content not in block.content + ) + ), + None, + ) if block: log.trace("A code block exists but has invalid ticks.") From ce39d176cb8d95ec13134b02be03b6db33789097 Mon Sep 17 00:00:00 2001 From: Dan Shernicoff Date: Wed, 24 Jun 2026 16:48:43 -0400 Subject: [PATCH 2/5] Fix formatting issue --- bot/exts/info/codeblock/_instructions.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bot/exts/info/codeblock/_instructions.py b/bot/exts/info/codeblock/_instructions.py index ae81ceaca7..4636653ff6 100644 --- a/bot/exts/info/codeblock/_instructions.py +++ b/bot/exts/info/codeblock/_instructions.py @@ -1,5 +1,6 @@ """This module generates and formats instructional messages about fixing Markdown code blocks.""" + from bot.exts.info.codeblock import _parsing from bot.log import get_logger @@ -7,7 +8,11 @@ # Make sure to escape any Markdown symbols here. _EXAMPLE_PY = "{lang}\nprint('Hello, world!')" -_EXAMPLE_CODE_BLOCKS = "\\`\\`\\`{content}\n\\`\\`\\`\n\n**This will result in the following:**\n```{content}```" +_EXAMPLE_CODE_BLOCKS = ( + "\\`\\`\\`{content}\n\\`\\`\\`\n\n + **This will result in the following:**\n + ```{content}```" +) def _get_example(language: str) -> str: @@ -33,7 +38,8 @@ def _get_bad_ticks_message(code_block: _parsing.CodeBlock) -> str | None: valid_ticks = f"\\{_parsing.BACKTICK}" * 3 instructions = ( - f"You are using the wrong character instead of backticks. Use {valid_ticks}, not `{code_block.ticks}`." + f"You are using the wrong character instead of backticks. " + f"Use {valid_ticks}, not `{code_block.ticks}`." ) log.trace("Check if the bad ticks code block also has issues with the language specifier.") From 5569f2ccc2e7ec3c792d2b2ec8410cf5ca97870b Mon Sep 17 00:00:00 2001 From: Dan Shernicoff Date: Wed, 24 Jun 2026 16:56:24 -0400 Subject: [PATCH 3/5] Formatting. --- bot/exts/info/codeblock/_instructions.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/bot/exts/info/codeblock/_instructions.py b/bot/exts/info/codeblock/_instructions.py index 4636653ff6..0602ae7572 100644 --- a/bot/exts/info/codeblock/_instructions.py +++ b/bot/exts/info/codeblock/_instructions.py @@ -1,6 +1,5 @@ """This module generates and formats instructional messages about fixing Markdown code blocks.""" - from bot.exts.info.codeblock import _parsing from bot.log import get_logger @@ -9,9 +8,9 @@ # Make sure to escape any Markdown symbols here. _EXAMPLE_PY = "{lang}\nprint('Hello, world!')" _EXAMPLE_CODE_BLOCKS = ( - "\\`\\`\\`{content}\n\\`\\`\\`\n\n - **This will result in the following:**\n - ```{content}```" + "\\`\\`\\`{content}\n\\`\\`\\`\n\n" + "**This will result in the following:**\n" + "```{content}```" ) @@ -38,7 +37,7 @@ def _get_bad_ticks_message(code_block: _parsing.CodeBlock) -> str | None: valid_ticks = f"\\{_parsing.BACKTICK}" * 3 instructions = ( - f"You are using the wrong character instead of backticks. " + "You are using the wrong character instead of backticks." f"Use {valid_ticks}, not `{code_block.ticks}`." ) From a2a58143397070a9f9471d8bcc15ca79c8b7677f Mon Sep 17 00:00:00 2001 From: Dan Shernicoff Date: Wed, 24 Jun 2026 16:58:19 -0400 Subject: [PATCH 4/5] Fix more formatting issues. --- bot/exts/info/codeblock/_instructions.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/bot/exts/info/codeblock/_instructions.py b/bot/exts/info/codeblock/_instructions.py index 0602ae7572..d9d90a9215 100644 --- a/bot/exts/info/codeblock/_instructions.py +++ b/bot/exts/info/codeblock/_instructions.py @@ -5,8 +5,7 @@ log = get_logger(__name__) -# Make sure to escape any Markdown symbols here. -_EXAMPLE_PY = "{lang}\nprint('Hello, world!')" +_EXAMPLE_PY = "{lang}\nprint('Hello, world!')" # Make sure to escape any Markdown symbols here. _EXAMPLE_CODE_BLOCKS = ( "\\`\\`\\`{content}\n\\`\\`\\`\n\n" "**This will result in the following:**\n" @@ -37,7 +36,7 @@ def _get_bad_ticks_message(code_block: _parsing.CodeBlock) -> str | None: valid_ticks = f"\\{_parsing.BACKTICK}" * 3 instructions = ( - "You are using the wrong character instead of backticks." + "You are using the wrong character instead of backticks. " f"Use {valid_ticks}, not `{code_block.ticks}`." ) From 009a5815cbde32449ca216d5b080193e6da3a831 Mon Sep 17 00:00:00 2001 From: Dan Shernicoff Date: Wed, 24 Jun 2026 16:58:50 -0400 Subject: [PATCH 5/5] Restore removed newline --- bot/exts/info/codeblock/_instructions.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bot/exts/info/codeblock/_instructions.py b/bot/exts/info/codeblock/_instructions.py index d9d90a9215..57c4b7ad95 100644 --- a/bot/exts/info/codeblock/_instructions.py +++ b/bot/exts/info/codeblock/_instructions.py @@ -1,5 +1,6 @@ """This module generates and formats instructional messages about fixing Markdown code blocks.""" + from bot.exts.info.codeblock import _parsing from bot.log import get_logger