From 5cf12406f73208e46e706a4972ce91c442e03cd8 Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Mon, 30 May 2022 17:38:32 -0700 Subject: [PATCH] Remove user ping from wordbot leaderboard When a user's name is used in the !wordbot leaderboard command, we make every effort to not ping them by interleaving zero-width space characters in the nickname. Signed-off-by: Alek Ratzloff --- plugins/wordbot.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/plugins/wordbot.py b/plugins/wordbot.py index cf1fa14..1daa8c9 100644 --- a/plugins/wordbot.py +++ b/plugins/wordbot.py @@ -15,6 +15,10 @@ from omnibot.plugin import Plugin log = logging.getLogger(__name__) +def denotify_nick(nick: str) -> str: + return "\u200b".join(nick) + + class Db: def __init__(self, path: Path): self.path = path @@ -258,7 +262,9 @@ class Wordbot(Plugin): ) # Only print out the top 5 for rank, (nick, score) in enumerate(leaderboard[:5]): - self.send_to(conn, channel, f"{rank + 1}. {nick}. {score}") + self.send_to( + conn, channel, f"{rank + 1}. {denotify_nick(nick)}. {score}" + ) # If the user isn't in the top 5, get their rank leaderboard_users = [user for user, _ in leaderboard] @@ -269,7 +275,9 @@ class Wordbot(Plugin): } rank, score = rankings[user] self.send_to(conn, channel, "...") - self.send_to(conn, channel, f"{rank + 1}. {user}. {score}") + self.send_to( + conn, channel, f"{rank + 1}. {denotify_nick(user)}. {score}" + ) case _: pass @@ -293,7 +301,8 @@ class Wordbot(Plugin): ) ) } - self.send_to(conn, channel, "Game over. Here were the scores:") + game_id = self.db.current_game(channel) + self.send_to(conn, channel, f"Game #{game_id} over. Here were the scores:") for user, score in scores: self.send_to(conn, channel, f"{rankings[score] + 1}. {user}. {score}")