aboutsummaryrefslogtreecommitdiffstats
path: root/slack/slack_message.py
diff options
context:
space:
mode:
Diffstat (limited to 'slack/slack_message.py')
-rw-r--r--slack/slack_message.py25
1 files changed, 22 insertions, 3 deletions
diff --git a/slack/slack_message.py b/slack/slack_message.py
index ad5e6b2..3c33864 100644
--- a/slack/slack_message.py
+++ b/slack/slack_message.py
@@ -3,6 +3,7 @@ from __future__ import annotations
import re
from typing import TYPE_CHECKING, List, Match, Optional
+import slack.slack_conversation
from slack.log import print_exception_once
from slack.python_compatibility import removeprefix
from slack.shared import shared
@@ -53,11 +54,21 @@ class SlackMessage:
return user.nick(colorize=True)
async def _lookup_item_id(self, item_id: str):
- if item_id.startswith("@"):
+ if item_id.startswith("#"):
+ return self.workspace.conversations[removeprefix(item_id, "#")]
+ elif item_id.startswith("@"):
return await self.workspace.users[removeprefix(item_id, "@")]
elif item_id.startswith("!subteam^"):
return await self.workspace.usergroups[removeprefix(item_id, "!subteam^")]
+ def _item_prefix(self, item_id: str):
+ if item_id.startswith("#") or item_id.startswith("@"):
+ return item_id[0]
+ elif item_id.startswith("!subteam^"):
+ return "@"
+ else:
+ return ""
+
async def _unfurl_refs(self, message: str) -> str:
re_mention = re.compile(r"<(?P<id>[^|>]+)(?:\|(?P<fallback_name>[^>]*))?>")
mention_matches = list(re_mention.finditer(message))
@@ -70,7 +81,11 @@ class SlackMessage:
def unfurl_ref(match: Match[str]):
item = items[match["id"]]
- if isinstance(item, SlackUser):
+ if isinstance(item, slack.slack_conversation.SlackConversation):
+ return with_color(
+ shared.config.color.channel_mention_color.value, "#" + item.name
+ )
+ elif isinstance(item, SlackUser):
return with_color(
shared.config.color.user_mention_color.value, "@" + item.nick()
)
@@ -80,7 +95,11 @@ class SlackMessage:
"@" + item.handle(),
)
elif match["fallback_name"]:
- return match["fallback_name"]
+ prefix = self._item_prefix(match["id"])
+ if match["fallback_name"].startswith(prefix):
+ return match["fallback_name"]
+ else:
+ return prefix + match["fallback_name"]
elif item:
print_exception_once(item)
return match[0]