diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2023-01-29 01:32:21 +0100 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2024-02-18 11:32:53 +0100 |
commit | f5d61f7102d368d21f20a55de4029d5531694a38 (patch) | |
tree | 10071958d4ea7eda70bb7cb9760a13d53fe6c106 /slack/slack_message.py | |
parent | aafa5218281ba2510a025c0c67ddd6caa244bca3 (diff) | |
download | wee-slack-f5d61f7102d368d21f20a55de4029d5531694a38.tar.gz |
Use user group fallback name
Diffstat (limited to 'slack/slack_message.py')
-rw-r--r-- | slack/slack_message.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/slack/slack_message.py b/slack/slack_message.py index cfae6cc..630ee35 100644 --- a/slack/slack_message.py +++ b/slack/slack_message.py @@ -52,7 +52,9 @@ class SlackMessage: return user.nick(colorize=True) async def _unfurl_refs(self, message: str) -> str: - re_mention = re.compile(r"<@(?P<user>[^>]+)>|<!subteam\^(?P<usergroup>[^>]+)>") + re_mention = re.compile( + r"<@(?P<user>[^>]+)>|<!subteam\^(?P<usergroup>[^|>]+)(?:\|(?P<usergroup_name>[^>]*))?>" + ) mention_matches = list(re_mention.finditer(message)) user_ids: List[str] = [ @@ -81,7 +83,7 @@ class SlackMessage: if match["user"]: return unfurl_user(match["user"]) elif match["usergroup"]: - return unfurl_usergroup(match["usergroup"]) + return unfurl_usergroup(match["usergroup"], match["usergroup_name"]) else: return match[0] @@ -95,13 +97,15 @@ class SlackMessage: print_exception_once(user) return f"@{user_id}" - def unfurl_usergroup(usergroup_id: str): + def unfurl_usergroup(usergroup_id: str, usergroup_fallback_name: Optional[str]): usergroup = usergroups[usergroup_id] if isinstance(usergroup, SlackUsergroup): return with_color( shared.config.color.usergroup_mention_color.value, "@" + usergroup.handle(), ) + elif usergroup_fallback_name: + return usergroup_fallback_name else: print_exception_once(usergroup) return f"@{usergroup_id}" |