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 <alekratz@gmail.com>
This commit is contained in:
2022-05-30 17:38:32 -07:00
parent de2b1c1761
commit 5cf12406f7

View File

@@ -15,6 +15,10 @@ from omnibot.plugin import Plugin
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
def denotify_nick(nick: str) -> str:
return "\u200b".join(nick)
class Db: class Db:
def __init__(self, path: Path): def __init__(self, path: Path):
self.path = path self.path = path
@@ -258,7 +262,9 @@ class Wordbot(Plugin):
) )
# Only print out the top 5 # Only print out the top 5
for rank, (nick, score) in enumerate(leaderboard[: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 # If the user isn't in the top 5, get their rank
leaderboard_users = [user for user, _ in leaderboard] leaderboard_users = [user for user, _ in leaderboard]
@@ -269,7 +275,9 @@ class Wordbot(Plugin):
} }
rank, score = rankings[user] rank, score = rankings[user]
self.send_to(conn, channel, "...") 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 _: case _:
pass 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: for user, score in scores:
self.send_to(conn, channel, f"{rankings[score] + 1}. {user}. {score}") self.send_to(conn, channel, f"{rankings[score] + 1}. {user}. {score}")