From e7009406c6fb45275b47172b301314affcaee485 Mon Sep 17 00:00:00 2001 From: ducklet Date: Sat, 7 Nov 2020 19:53:36 +0100 Subject: [PATCH] prost: harden code against unicode input problems --- hotdog/command/prost.py | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/hotdog/command/prost.py b/hotdog/command/prost.py index 4204f22..13d0200 100644 --- a/hotdog/command/prost.py +++ b/hotdog/command/prost.py @@ -8,28 +8,31 @@ def init(bot): bot.on_message(handle) +vs16 = "\ufe0f" # see https://en.wikipedia.org/wiki/Variation_Selectors_%28Unicode_block%29 emojis = { - "☕️", - "🍵", - "🍶", - "🍷", - "🍸", - "🍹", - "🍺", - "🍻", - "🍼", - "🍾", - "🥂", - "🥃", - "🥛", - "🥤", - "🧃", - "🧉", + e.rstrip(vs16) + for e in { + "☕", + "🍵", + "🍶", + "🍷", + "🍸", + "🍹", + "🍺", + "🍻", + "🍼", + "🍾", + "🥂", + "🥃", + "🥛", + "🥤", + "🧃", + "🧉", + } } async def handle(message: Message): - vs16 = "\ufe0f" # see https://en.wikipedia.org/wiki/Variation_Selectors_%28Unicode_block%29 is_drinkmoji = message.text.rstrip(vs16) in emojis if not (message.tokens.str(0).startswith("PR!") or is_drinkmoji): return