aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--slack/config.py7
-rw-r--r--slack/slack_message.py25
2 files changed, 29 insertions, 3 deletions
diff --git a/slack/config.py b/slack/config.py
index 6470816..ae31350 100644
--- a/slack/config.py
+++ b/slack/config.py
@@ -21,6 +21,13 @@ class SlackConfigSectionColor:
def __init__(self, weechat_config: WeeChatConfig):
self._section = WeeChatSection(weechat_config, "color")
+ self.channel_mention_color = WeeChatOption(
+ self._section,
+ "channel_mention_color",
+ "text color for mentioned channel names in the chat",
+ WeeChatColor("blue"),
+ )
+
self.disconnected = WeeChatOption(
self._section,
"disconnected",
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]