aboutsummaryrefslogtreecommitdiffstats
path: root/slack/slack_message.py
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2023-09-19 01:08:32 +0200
committerTrygve Aaberge <trygveaa@gmail.com>2024-02-18 11:32:54 +0100
commitd094323c212587c8bdb68fda7dac2f053143ad32 (patch)
treedc22c4f9a72bffd49d008bcdc33c54db88a4a20b /slack/slack_message.py
parent15d222cfe645e0f7b62738077cce534285f0169e (diff)
downloadwee-slack-d094323c212587c8bdb68fda7dac2f053143ad32.tar.gz
If a message has a user, use that even though it's a bot_message
Messages from Slackbot apparently have both a user and a bot_id, and sometimes have the subtype bot_message, other times not. However, the bot_id is B01 which gives bot_not_found when trying to look it up. I see that the web client shows it with the user profile, and doesn't show the message as a bot message, so do that here as well to match it and avoid the invalid bot_id.
Diffstat (limited to 'slack/slack_message.py')
-rw-r--r--slack/slack_message.py26
1 files changed, 9 insertions, 17 deletions
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