diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2023-09-17 21:54:51 +0200 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2024-02-18 11:32:54 +0100 |
commit | 1672b9038226ac2001cd89bfcc8d096b995d4bbe (patch) | |
tree | 68166c0f5b225296ed30609bf9bf97f539e004e7 /slack/slack_message.py | |
parent | 0f4d849576812a249ee3497ddac7ffdc42f7f7b3 (diff) | |
download | wee-slack-1672b9038226ac2001cd89bfcc8d096b995d4bbe.tar.gz |
Add/remove nicks from nicklist when messages are printed
This ensures that all nicks that have typed in the channel and still is
in it are in the nicklist, so they are not colored as offline. It also
removes nicks from the nicklist when they leave a channel.
Diffstat (limited to 'slack/slack_message.py')
-rw-r--r-- | slack/slack_message.py | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/slack/slack_message.py b/slack/slack_message.py index bb4d141..6c97e24 100644 --- a/slack/slack_message.py +++ b/slack/slack_message.py @@ -17,7 +17,7 @@ from slack.error import ( from slack.log import print_error, print_exception_once from slack.python_compatibility import removeprefix, removesuffix from slack.shared import shared -from slack.slack_user import format_bot_nick, nick_color +from slack.slack_user import SlackBot, SlackUser, format_bot_nick, nick_color from slack.task import gather from slack.util import with_color from slack.weechat_config import WeeChatColor @@ -152,6 +152,11 @@ class SlackMessage: return self.conversation.message_hashes[self.ts] @property + def subtype(self): + if "subtype" in self._message_json: + return self._message_json["subtype"] + + @property def thread_ts(self) -> Optional[SlackTs]: return ( SlackTs(self._message_json["thread_ts"]) @@ -195,6 +200,16 @@ class SlackMessage: 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: + return await self.workspace.users[self._message_json["user"]] + + @property def priority(self) -> MessagePriority: return MessagePriority.MESSAGE @@ -245,7 +260,7 @@ class SlackMessage: async def tags(self, backlog: bool = False) -> str: # TODO: Add tags for highlight - nick = await self._nick(colorize=False, only_nick=True) + nick = await self.nick(colorize=False, only_nick=True) tags = [f"slack_ts_{self.ts}", f"nick_{nick}"] if self.sender_user_id: @@ -302,7 +317,7 @@ class SlackMessage: self._rendered = f"{prefix}\t{message}" return self._rendered - async def _nick(self, colorize: bool = True, only_nick: bool = False) -> str: + 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" @@ -327,7 +342,7 @@ class SlackMessage: elif self._message_json.get("subtype") == "me_message": return removesuffix(weechat.prefix("action"), "\t") else: - return await self._nick(colorize=colorize, only_nick=only_nick) + return await self.nick(colorize=colorize, only_nick=only_nick) async def render_prefix(self) -> str: if self._rendered_prefix is not None: @@ -363,7 +378,7 @@ class SlackMessage: else: inviter_text = "" - return f"{await self._nick()} {text_action} {text_conversation_name}{inviter_text}" + return f"{await self.nick()} {text_action} {text_conversation_name}{inviter_text}" elif ( "subtype" in self._message_json @@ -396,7 +411,7 @@ class SlackMessage: full_text = "\n".join([text_with_files] + attachment_texts) if self._message_json.get("subtype") == "me_message": - return f"{await self._nick()} {full_text}" + return f"{await self.nick()} {full_text}" else: return full_text |