26 lines
815 B
Python
26 lines
815 B
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
from yuxi.channels.models import MentionsInfo
|
||
|
|
|
||
|
|
|
||
|
|
def parse_mentions(message: dict, bot_user: str = "") -> MentionsInfo:
|
||
|
|
annotations = message.get("annotations", [])
|
||
|
|
mentioned_ids = [
|
||
|
|
a.get("userMention", {}).get("user", {}).get("name", "") for a in annotations if a.get("type") == "USER_MENTION"
|
||
|
|
]
|
||
|
|
is_at_bot = False
|
||
|
|
for a in annotations:
|
||
|
|
if a.get("type") != "USER_MENTION":
|
||
|
|
continue
|
||
|
|
um = a.get("userMention", {})
|
||
|
|
if um.get("type") == "BOT":
|
||
|
|
is_at_bot = True
|
||
|
|
break
|
||
|
|
if bot_user and um.get("user", {}).get("name", "") == bot_user:
|
||
|
|
is_at_bot = True
|
||
|
|
break
|
||
|
|
return MentionsInfo(
|
||
|
|
mentioned_user_ids=mentioned_ids,
|
||
|
|
is_bot_mentioned=is_at_bot,
|
||
|
|
)
|