aboutsummaryrefslogtreecommitdiffstats
path: root/slack/slack_message.py
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2023-01-15 14:18:37 +0100
committerTrygve Aaberge <trygveaa@gmail.com>2024-02-18 11:32:53 +0100
commit988c7770e2c70e0cdf8268dabb4ef6f02ce2ca99 (patch)
tree9fd61b1bc60d614904a1d5c51c6c157c10850394 /slack/slack_message.py
parent7b9cf4d9278f584c4ce754e3dfbbcd245b1f9985 (diff)
downloadwee-slack-988c7770e2c70e0cdf8268dabb4ef6f02ce2ca99.tar.gz
Show nick suffix for bots
Diffstat (limited to 'slack/slack_message.py')
-rw-r--r--slack/slack_message.py18
1 files changed, 14 insertions, 4 deletions
diff --git a/slack/slack_message.py b/slack/slack_message.py
index d6431d7..3c5383b 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
+from slack.slack_user import format_bot_nick
from slack.task import gather
if TYPE_CHECKING:
@@ -23,12 +24,21 @@ class SlackMessage:
return self.conversation.workspace
async def render_message(self):
- message = await self._unfurl_refs(self._message_json["text"])
- if "user" in self._message_json:
+ if (
+ "subtype" in self._message_json
+ and self._message_json["subtype"] == "bot_message"
+ ):
+ username = self._message_json.get("username")
+ if username:
+ prefix = format_bot_nick(username, colorize=True)
+ else:
+ bot = await self.workspace.bots[self._message_json["bot_id"]]
+ prefix = bot.nick(colorize=True)
+ else:
user = await self.workspace.users[self._message_json["user"]]
prefix = user.nick(colorize=True)
- else:
- prefix = "bot"
+
+ message = await self._unfurl_refs(self._message_json["text"])
return f"{prefix}\t{message}"