prost: harden code against unicode input problems

This commit is contained in:
ducklet 2020-11-07 19:53:36 +01:00
parent 798b339b4b
commit e7009406c6

View file

@ -8,28 +8,31 @@ def init(bot):
bot.on_message(handle) bot.on_message(handle)
vs16 = "\ufe0f" # see https://en.wikipedia.org/wiki/Variation_Selectors_%28Unicode_block%29
emojis = { emojis = {
"☕️", e.rstrip(vs16)
"🍵", for e in {
"🍶", "",
"🍷", "🍵",
"🍸", "🍶",
"🍹", "🍷",
"🍺", "🍸",
"🍻", "🍹",
"🍼", "🍺",
"🍾", "🍻",
"🥂", "🍼",
"🥃", "🍾",
"🥛", "🥂",
"🥤", "🥃",
"🧃", "🥛",
"🧉", "🥤",
"🧃",
"🧉",
}
} }
async def handle(message: Message): 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 is_drinkmoji = message.text.rstrip(vs16) in emojis
if not (message.tokens.str(0).startswith("PR!") or is_drinkmoji): if not (message.tokens.str(0).startswith("PR!") or is_drinkmoji):
return return