diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2023-01-28 16:52:18 +0100 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2024-02-18 11:32:53 +0100 |
commit | 55643a7088e4fa8e7b5fd0aea62021975da6a4f0 (patch) | |
tree | 0c66ad9005bee1b7c0d25f0ede38b5d988a5044d /slack/slack_message.py | |
parent | c449329680b971d049d53f67dd25dd10a6be184f (diff) | |
download | wee-slack-55643a7088e4fa8e7b5fd0aea62021975da6a4f0.tar.gz |
Fallback to using @<user_id> if user is not found in unfurl_refs
This is what the official web client does.
Diffstat (limited to 'slack/slack_message.py')
-rw-r--r-- | slack/slack_message.py | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/slack/slack_message.py b/slack/slack_message.py index 0757761..db5c6cf 100644 --- a/slack/slack_message.py +++ b/slack/slack_message.py @@ -3,7 +3,7 @@ from __future__ import annotations import re from typing import TYPE_CHECKING, List, Optional -from slack.slack_user import format_bot_nick +from slack.slack_user import SlackUser, format_bot_nick from slack.task import gather if TYPE_CHECKING: @@ -52,11 +52,13 @@ class SlackMessage: re_user = re.compile("<@([^>]+)>") user_ids: List[str] = re_user.findall(message) users_list = await gather( - *(self.workspace.users[user_id] for user_id in user_ids) + *(self.workspace.users[user_id] for user_id in user_ids), + return_exceptions=True, ) users = dict(zip(user_ids, users_list)) def unfurl_user(user_id: str): - return "@" + users[user_id].nick() + user = users[user_id] + return "@" + user.nick() if isinstance(user, SlackUser) else f"@{user_id}" return re_user.sub(lambda match: unfurl_user(match.group(1)), message) |