Skip to content

Commit

Permalink
Abbreviate codeblock instructions; remove ability to dismiss the inst…
Browse files Browse the repository at this point in the history
…ructions with emoji.

The more concise instructions are intended to be easier to read and increase the rate of followthru. That the instructions cannot be dismissed is intended to make them harder to ignore.
  • Loading branch information
swfarnsworth committed Jan 8, 2025
1 parent 41d15cc commit d4002eb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 25 deletions.
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."

return instructions

0 comments on commit d4002eb

Please sign in to comment.