diff options
| author | 2020-04-15 21:07:38 -0700 | |
|---|---|---|
| committer | 2020-06-13 11:21:04 -0700 | |
| commit | 381872deedd39c171f3fff3312c6049c19c4371f (patch) | |
| tree | 7736f62db0223515820ef3f6259f7f7b7609a19f | |
| parent | Code block: simplify log message (diff) | |
Code block: ignore if code block has *any* language
If the code was valid Python syntax, the guide embed would be sent
despite a non-Python language being explicitly specified for the code
block by the message author.
* Make the code block language regex a compiled pattern constant
Fixes #829
| -rw-r--r-- | bot/cogs/codeblock/cog.py | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/bot/cogs/codeblock/cog.py b/bot/cogs/codeblock/cog.py index c49d7574c..fc515c8df 100644 --- a/bot/cogs/codeblock/cog.py +++ b/bot/cogs/codeblock/cog.py @@ -15,6 +15,7 @@ from bot.utils.messages import wait_for_deletion log = logging.getLogger(__name__) RE_MARKDOWN = re.compile(r'([*_~`|>])') +RE_CODE_BLOCK_LANGUAGE = re.compile(r"```(?:[^\W_])\n(.*?)```", re.DOTALL) INVALID_BACKTICKS = { "'''", '"""', @@ -57,11 +58,8 @@ class CodeBlockCog(Cog, name="Code Block"): """ if msg.count("\n") >= 3: # Filtering valid Python codeblocks and exiting if a valid Python codeblock is found. - if re.search("```(?:py|python)\n(.*?)```", msg, re.IGNORECASE | re.DOTALL) and not bad_ticks: - log.trace( - "Someone wrote a message that was already a " - "valid Python syntax highlighted code block. No action taken." - ) + if RE_CODE_BLOCK_LANGUAGE.search(msg) and not bad_ticks: + log.trace("Code block already has valid syntax highlighting; no action taken") return None else: |