Skip to content

Escape nicknames in patrick responses. - #67

Open
JoBeGaming wants to merge 12 commits into
OpenRedstoneEngineers:mainfrom
JoBeGaming:escape-usernames
Open

JoBeGaming wants to merge 12 commits into
OpenRedstoneEngineers:mainfrom
JoBeGaming:escape-usernames

Conversation

@JoBeGaming

@JoBeGaming JoBeGaming commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

See https://discord.com/channels/116914772766752769/165640273810948097/1544019167798239233 for embeds, and https://discord.com/channels/116914772766752769/1216162486152335471/1544010187546038282 as well as https://discord.com/channels/116914772766752769/1216162486152335471/1544010104511266841 for nickame usage in normal commands.

For tests, the output of the test attached was sent in https://discord.com/channels/116914772766752769/165640273810948097/1544010979694608516, and seems to raise no issues with Discord Markdown. See https://discord.com/channels/116914772766752769/165640273810948097/1544023339042087113 for tests related to links. Note that I've not implemented direct link escaping (https://www.youtube.com) yet.

assert escape_nickname("> job") == r"\> job"
assert escape_nickname("*job*") == r"\*job\*"
assert escape_nickname("**job**") == r"\*\*job\*\*"
assert escape_nickname("_job_") == r"\_job\_"
assert escape_nickname("__job__") == r"\_\_job\_\_"
assert escape_nickname("`job`") == r"\`job\`"
assert escape_nickname("> job") == r"\> job"
assert escape_nickname("~~job~~") == r"\~\~job\~\~"
assert escape_nickname("||job||") == r"\|\|job\|\|"

(Edit: Fix name of function in tests)

@JoBeGaming
JoBeGaming marked this pull request as draft September 11, 2026 16:55

@Nickster258 Nickster258 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Probably shouldn't escape the logged statements. At the same time, would be worth logging the user ID in the event message.

Comment thread patrick.py Outdated
Comment thread patrick.py Outdated
Comment thread patrick.py Outdated
@Wueffi

Wueffi commented Sep 15, 2026

Copy link
Copy Markdown
Member

67

Comment thread util.py Outdated
@JoBeGaming

Copy link
Copy Markdown
Contributor Author

Weird how my commit from VSC got added, but the reply didn't get send...

@JoBeGaming
JoBeGaming marked this pull request as ready for review September 15, 2026 10:16
@JoBeGaming

Copy link
Copy Markdown
Contributor Author

Ok seems like I've forgotten to add cases such as # job, - job and -# job as I've primarily focused on names possible in Minecraft. I've updated the regex accordingly, although we might actually be better off using the function provided by discord.py later, if necessary.

@JoBeGaming

JoBeGaming commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author
assert escape_nickname("> job") == r"\> job"
assert escape_nickname("*job*") == r"\*job\*"
assert escape_nickname("**job**") == r"\*\*job\*\*"
assert escape_nickname("_job_") == r"\_job\_"
assert escape_nickname("__job__") == r"\_\_job\_\_"
assert escape_nickname("`job`") == r"\`job\`"
assert escape_nickname("> job") == r"\> job"
assert escape_nickname("~~job~~") == r"\~\~job\~\~"
assert escape_nickname("||job||") == r"\|\|job\|\|"
assert escape_nickname("# job") == r"\# job"
assert escape_nickname("- job") == r"\- job"
assert escape_nickname("-# job") == r"\-\# job"

(Updated test-cases if anyone is interested)

@Wueffi Wueffi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Holy critical bug

Comment thread patrick.py Outdated
Comment thread patrick.py Outdated
Comment thread util.py Outdated
@JoBeGaming
JoBeGaming requested a review from Wueffi September 20, 2026 15:15
Comment thread patrick.py
if matches:
logger.info(
f"Automod triggered for user {message.author.display_name} with message {message.content}"
f"Automod triggered for user {user_log_repr(message.author)} with message {message.content}"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Minor question. Most other log messages had ' used as quotes around the user part. Should we keep that here too? Although i feel like 'Name' (1234) would be the best option instead of 'Name (1234)', meaning @Wueffi was wrong and I should probably have user_log_repr return f"'{user.display_name}' ({user.id})" instead.

Comment thread util.py
if message.content.removeprefix(prefix) in commands:
bot.logger.info(
f"User '{message.author.display_name}' ran custom command '{message.content[1:]}'"
f"User {user_log_repr(message.author)} ran custom command '{message.content[1:]}'"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Also user_log_repr itself should be wrapped in ', I should probably add that here too.

@Wueffi Wueffi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The rest lgtm

Comment thread util.py
id, so log messages are the same as in chattore.
"""

return f"{user.display_name} ({user.id})"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I agree that it may be best to insert the ' here for us to keep a consistent scheme

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok so i should merge JoBeGaming#1 into the PR branch?

Comment thread patrick.py
# This is provided by discord.py and ensures that the context is valid for regular command processing
self.logger.info(
f"User '{message.author.display_name}' ran command '{ctx.command.name}'"
f"User '{user_log_repr(message.author)}' ran command '{ctx.command.name}'"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Then you can remove this

Comment thread patrick.py
# A prefix was found, but no (custom) command was found. This means the user is trying to run a command that does not exist.
self.logger.info(
f"User '{ctx.author.display_name}' attempted to run an unrecognized command: '{ctx.message.content[1:]}'"
f"User '{user_log_repr(ctx.author)}' attempted to run an unrecognized command: '{ctx.message.content[1:]}'"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

and this

Comment thread cogs/errorhandler.py
elif isinstance(error, commands.CommandNotFound):
self.bot.logger.info(
f"User '{ctx.author.display_name}' attempted to run an unrecognized command: '{ctx.message.content[1:]}'"
f"User '{user_log_repr(ctx.author)}' attempted to run an unrecognized command: '{ctx.message.content[1:]}'"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

aswell as this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants