Skip to content

Commit d2fcb34

Browse files
authored
Fix issue with apparent codeblock within other codeblock (#3527)
* 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. * Fix formatting issue * Formatting. * Fix more formatting issues. * Restore removed newline
1 parent 6700250 commit d2fcb34

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

bot/exts/info/codeblock/_instructions.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,23 @@ def get_instructions(content: str) -> str | None:
148148
instructions = _get_no_ticks_message(content)
149149
else:
150150
log.trace("Searching results for a code block with invalid ticks.")
151-
block = next((block for block in blocks if block.tick != _parsing.BACKTICK), None)
151+
bad_ticks = [block for block in blocks if block.tick != _parsing.BACKTICK]
152+
block = None
153+
if bad_ticks:
154+
block = next(
155+
(
156+
bad_tick
157+
for bad_tick in bad_ticks
158+
if any(
159+
block
160+
for block in blocks
161+
if block != bad_tick
162+
and bad_tick.content != block.content
163+
and bad_tick.content not in block.content
164+
)
165+
),
166+
None,
167+
)
152168

153169
if block:
154170
log.trace("A code block exists but has invalid ticks.")

0 commit comments

Comments
 (0)