Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 3 additions & 4 deletions bot/exts/info/codeblock/_cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ class CodeBlockCog(Cog, name="Code Block"):
When an issue is detected, an embed is sent containing specific instructions on fixing what
is wrong. If the user edits their message to fix the code block, the instructions will be
removed. If they fail to fix the code block with an edit, the instructions will be updated to
show what is still incorrect after the user's edit. The embed can be manually deleted with a
reaction. Otherwise, it will automatically be removed after 5 minutes.
show what is still incorrect after the user's edit. Otherwise, it will automatically be removed after 5 minutes.

The cog only detects messages in whitelisted channels. Channels may also have a cooldown on the
instructions being sent. Note all help channels are also whitelisted with cooldowns enabled.
Expand All @@ -64,7 +63,7 @@ def __init__(self, bot: Bot):
@staticmethod
def create_embed(instructions: str) -> discord.Embed:
"""Return an embed which displays code block formatting `instructions`."""
return discord.Embed(description=instructions)
return discord.Embed(description=instructions, title="Please edit your message to use a code block")

async def get_sent_instructions(self, payload: RawMessageUpdateEvent) -> Message | None:
"""
Expand Down Expand Up @@ -114,7 +113,7 @@ async def send_instructions(self, message: discord.Message, instructions: str) -
bot_message = await message.channel.send(f"Hey {message.author.mention}!", embed=embed)
self.codeblock_message_ids[message.id] = bot_message.id

scheduling.create_task(wait_for_deletion(bot_message, (message.author.id,)))
scheduling.create_task(wait_for_deletion(bot_message, tuple(), attach_emojis=False))

# Increase amount of codeblock correction in stats
self.bot.stats.incr("codeblock_corrections")
Expand Down
26 changes: 5 additions & 21 deletions bot/exts/info/codeblock/_instructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ def _get_bad_ticks_message(code_block: _parsing.CodeBlock) -> str | None:

valid_ticks = f"\\{_parsing.BACKTICK}" * 3
instructions = (
"It looks like you are trying to paste code into this channel.\n\n"
"You seem to be using the wrong symbols to indicate where the code block should start. "
f"The correct symbols would be {valid_ticks}, not `{code_block.tick * 3}`."
"You are using the wrong character instead of backticks. "
f"Use {valid_ticks}, not `{code_block.tick * 3}`."
)

log.trace("Check if the bad ticks code block also has issues with the language specifier.")
Expand All @@ -59,8 +58,6 @@ def _get_bad_ticks_message(code_block: _parsing.CodeBlock) -> str | None:
instructions += "\n\nFurthermore, " + addition_msg[0].lower() + addition_msg[1:]
else:
log.trace("No issues with the language specifier found.")
example_blocks = _get_example(code_block.language)
instructions += f"\n\n**Here is an example of how it should look:**\n{example_blocks}"

return instructions

Expand All @@ -71,13 +68,7 @@ def _get_no_ticks_message(content: str) -> str | None:

if _parsing.is_python_code(content):
example_blocks = _get_example("py")
return (
"It looks like you're trying to paste code into this channel.\n\n"
"Discord has support for Markdown, which allows you to post code with full "
"syntax highlighting. Please use these whenever you paste code, as this "
"helps improve the legibility and makes it easier for us to help you.\n\n"
f"**To do this, use the following method:**\n{example_blocks}"
)
return example_blocks
log.trace("Aborting missing code block instructions: content is not Python code.")
return None

Expand Down Expand Up @@ -135,12 +126,8 @@ def _get_no_lang_message(content: str) -> str | None:
example_blocks = _get_example("py")

# Note that _get_bad_ticks_message expects the first line to have two newlines.
return (
"It looks like you pasted Python code without syntax highlighting.\n\n"
"Please use syntax highlighting to improve the legibility of your code and make "
"it easier for us to help you.\n\n"
f"**To do this, use the following method:**\n{example_blocks}"
)
return f"Please add a `py` after the three backticks.\n\n{example_blocks}"

log.trace("Aborting missing language instructions: content is not Python code.")
return None

Expand Down Expand Up @@ -177,7 +164,4 @@ def get_instructions(content: str) -> str | None:
if not instructions:
instructions = _get_no_lang_message(block.content)

if instructions:
instructions += "\nYou can **edit your original message** to correct your code block."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think this line was ineffective? The intent was to avoid spamming the channel with several attempts to fix their message. I don't know a better way to communicate this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved this instruction to the title for the embed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I need to read more carefully, sorry!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem; thank you for having written the original code in such a way that the changes in this PR were straightforward to make.


return instructions
Loading