aboutsummaryrefslogtreecommitdiffstats
path: root/slack
diff options
context:
space:
mode:
Diffstat (limited to 'slack')
-rw-r--r--slack/slack_conversation.py6
-rw-r--r--slack/slack_message.py26
-rw-r--r--slack/slack_thread.py6
3 files changed, 19 insertions, 19 deletions
diff --git a/slack/slack_conversation.py b/slack/slack_conversation.py
index fefcdfa..5ccd85d 100644
--- a/slack/slack_conversation.py
+++ b/slack/slack_conversation.py
@@ -302,7 +302,11 @@ class SlackConversation(SlackBuffer):
sender_user_ids = [m.sender_user_id for m in messages if m.sender_user_id]
self.workspace.users.initialize_items(sender_user_ids)
- sender_bot_ids = [m.sender_bot_id for m in messages if m.sender_bot_id]
+ sender_bot_ids = [
+ m.sender_bot_id
+ for m in messages
+ if m.sender_bot_id and not m.sender_user_id
+ ]
self.workspace.bots.initialize_items(sender_bot_ids)
await gather(*(message.render(self.context) for message in messages))
diff --git a/slack/slack_message.py b/slack/slack_message.py
index bda8c54..1d0a4ab 100644
--- a/slack/slack_message.py
+++ b/slack/slack_message.py
@@ -203,23 +203,18 @@ class SlackMessage:
@property
def sender_user_id(self) -> Optional[str]:
- if not self.is_bot_message:
- return self._message_json.get("user")
+ return self._message_json.get("user")
@property
def sender_bot_id(self) -> Optional[str]:
- if self.is_bot_message:
- return self._message_json.get("bot_id")
+ return self._message_json.get("bot_id")
@property
async def sender(self) -> Union[SlackUser, SlackBot]:
- if (
- "subtype" in self._message_json
- and self._message_json["subtype"] == "bot_message"
- ):
- return await self.workspace.bots[self._message_json["bot_id"]]
- else:
+ if "user" in self._message_json:
return await self.workspace.users[self._message_json["user"]]
+ else:
+ return await self.workspace.bots[self._message_json["bot_id"]]
@property
def priority(self) -> MessagePriority:
@@ -352,19 +347,16 @@ class SlackMessage:
return self._rendered
async def nick(self, colorize: bool = True, only_nick: bool = False) -> str:
- if (
- "subtype" in self._message_json
- and self._message_json["subtype"] == "bot_message"
- ):
+ if "user" in self._message_json:
+ user = await self.workspace.users[self._message_json["user"]]
+ return user.nick(colorize=colorize, only_nick=only_nick)
+ else:
username = self._message_json.get("username")
if username:
return format_bot_nick(username, colorize=colorize, only_nick=only_nick)
else:
bot = await self.workspace.bots[self._message_json["bot_id"]]
return bot.nick(colorize=colorize, only_nick=only_nick)
- else:
- user = await self.workspace.users[self._message_json["user"]]
- return user.nick(colorize=colorize, only_nick=only_nick)
async def _render_prefix(
self, colorize: bool = True, only_nick: bool = False
diff --git a/slack/slack_thread.py b/slack/slack_thread.py
index fbbeb21..1c94c7d 100644
--- a/slack/slack_thread.py
+++ b/slack/slack_thread.py
@@ -76,7 +76,11 @@ class SlackThread(SlackBuffer):
sender_user_ids = [m.sender_user_id for m in messages if m.sender_user_id]
self.workspace.users.initialize_items(sender_user_ids)
- sender_bot_ids = [m.sender_bot_id for m in messages if m.sender_bot_id]
+ sender_bot_ids = [
+ m.sender_bot_id
+ for m in messages
+ if m.sender_bot_id and not m.sender_user_id
+ ]
self.workspace.bots.initialize_items(sender_bot_ids)
await gather(*(message.render(self.context) for message in messages))