Skip to content

Commit 8311343

Browse files
authored
Merge pull request #3232 from python-discord/codeblock-instructions
Abbreviate codeblock instructions; remove ability to dismiss the inst…
2 parents 41d15cc + 0f3239a commit 8311343

File tree

2 files changed

+12
-31
lines changed

2 files changed

+12
-31
lines changed

bot/exts/info/codeblock/_cog.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ class CodeBlockCog(Cog, name="Code Block"):
4343
When an issue is detected, an embed is sent containing specific instructions on fixing what
4444
is wrong. If the user edits their message to fix the code block, the instructions will be
4545
removed. If they fail to fix the code block with an edit, the instructions will be updated to
46-
show what is still incorrect after the user's edit. The embed can be manually deleted with a
47-
reaction. Otherwise, it will automatically be removed after 5 minutes.
46+
show what is still incorrect after the user's edit. Otherwise, it will automatically be removed after 5 minutes.
4847
4948
The cog only detects messages in whitelisted channels. Channels may also have a cooldown on the
5049
instructions being sent. Note all help channels are also whitelisted with cooldowns enabled.
@@ -64,7 +63,7 @@ def __init__(self, bot: Bot):
6463
@staticmethod
6564
def create_embed(instructions: str) -> discord.Embed:
6665
"""Return an embed which displays code block formatting `instructions`."""
67-
return discord.Embed(description=instructions)
66+
return discord.Embed(description=instructions, title="Please edit your message to use a code block")
6867

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

117-
scheduling.create_task(wait_for_deletion(bot_message, (message.author.id,)))
116+
scheduling.create_task(wait_for_deletion(bot_message, tuple(), attach_emojis=False))
118117

119118
# Increase amount of codeblock correction in stats
120119
self.bot.stats.incr("codeblock_corrections")

bot/exts/info/codeblock/_instructions.py

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ def _get_bad_ticks_message(code_block: _parsing.CodeBlock) -> str | None:
3737

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

4544
log.trace("Check if the bad ticks code block also has issues with the language specifier.")
@@ -53,14 +52,12 @@ def _get_bad_ticks_message(code_block: _parsing.CodeBlock) -> str | None:
5352
log.trace("Language specifier issue found; appending additional instructions.")
5453

5554
# The first line has double newlines which are not desirable when appending the msg.
56-
addition_msg = addition_msg.replace("\n\n", " ", 1)
55+
addition_msg = addition_msg.replace("\n\n", " ", 1).strip()
5756

5857
# Make the first character of the addition lower case.
59-
instructions += "\n\nFurthermore, " + addition_msg[0].lower() + addition_msg[1:]
58+
instructions += "\n\nAlso, " + addition_msg[0].lower() + addition_msg[1:]
6059
else:
6160
log.trace("No issues with the language specifier found.")
62-
example_blocks = _get_example(code_block.language)
63-
instructions += f"\n\n**Here is an example of how it should look:**\n{example_blocks}"
6461

6562
return instructions
6663

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

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

@@ -115,10 +106,8 @@ def _get_bad_lang_message(content: str) -> str | None:
115106
example_blocks = _get_example(language)
116107

117108
# Note that _get_bad_ticks_message expects the first line to have two newlines.
118-
return (
119-
f"It looks like you incorrectly specified a language for your code block.\n\n{lines}"
120-
f"\n\n**Here is an example of how it should look:**\n{example_blocks}"
121-
)
109+
return f"\n\n{lines}\n\n**Here is an example of how it should look:**\n{example_blocks}"
110+
122111
log.trace("Nothing wrong with the language specifier; no instructions to return.")
123112
return None
124113

@@ -135,12 +124,8 @@ def _get_no_lang_message(content: str) -> str | None:
135124
example_blocks = _get_example("py")
136125

137126
# Note that _get_bad_ticks_message expects the first line to have two newlines.
138-
return (
139-
"It looks like you pasted Python code without syntax highlighting.\n\n"
140-
"Please use syntax highlighting to improve the legibility of your code and make "
141-
"it easier for us to help you.\n\n"
142-
f"**To do this, use the following method:**\n{example_blocks}"
143-
)
127+
return f"\n\nAdd a `py` after the three backticks.\n\n{example_blocks}"
128+
144129
log.trace("Aborting missing language instructions: content is not Python code.")
145130
return None
146131

@@ -177,7 +162,4 @@ def get_instructions(content: str) -> str | None:
177162
if not instructions:
178163
instructions = _get_no_lang_message(block.content)
179164

180-
if instructions:
181-
instructions += "\nYou can **edit your original message** to correct your code block."
182-
183165
return instructions

0 commit comments

Comments
 (0)