From e1c77163b5ddfc59681fc08c189952f58b22fb77 Mon Sep 17 00:00:00 2001 From: SonodaHanami Date: Sat, 5 Sep 2020 00:44:05 +0800 Subject: [PATCH] fix discord @ message without '!' --- kokkoro/bot/discord/discord_util.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/kokkoro/bot/discord/discord_util.py b/kokkoro/bot/discord/discord_util.py index a7b0f10..bc29d06 100644 --- a/kokkoro/bot/discord/discord_util.py +++ b/kokkoro/bot/discord/discord_util.py @@ -12,7 +12,7 @@ def remove_mention_me(raw_message) -> (str, bool): return raw_message.replace(MENTION_BOT, "").strip(), True return raw_message, False -dc_at_pattern = r'<@![a-z0-9A-Z]+>' +dc_at_pattern = r'<@!?[a-z0-9A-Z]+>' def normalize_message(raw_message: str) -> str: """ 规范化 at 信息,"<@!123> waht<@!312>a12" => "@123 waht @312 a12" @@ -26,4 +26,7 @@ def normalize_at(raw_at): """ 规范化 at 信息,"<@!123>" => " @123 " """ - return f' @{raw_at[3:-1]} ' \ No newline at end of file + if '!' in raw_at: + return f' @{raw_at[3:-1]} ' + else: + return f' @{raw_at[2:-1]} '