diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2023-01-14 22:24:44 +0100 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2024-02-18 11:32:53 +0100 |
commit | 1906b75a92fcdc441e891546cc9cc97a2e621495 (patch) | |
tree | 15ed1ef3a8d80b972a3fb4c3e490574b50d24c3c /slack/slack_message.py | |
parent | a703cb532e9ed7ac404f48fa292903f392484805 (diff) | |
download | wee-slack-1906b75a92fcdc441e891546cc9cc97a2e621495.tar.gz |
Some cleanup and make some properties private
Diffstat (limited to 'slack/slack_message.py')
-rw-r--r-- | slack/slack_message.py | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/slack/slack_message.py b/slack/slack_message.py index abfa403..6903f26 100644 --- a/slack/slack_message.py +++ b/slack/slack_message.py @@ -9,34 +9,30 @@ if TYPE_CHECKING: from slack_api.slack_conversations_history import SlackMessage as SlackMessageDict from slack.slack_conversation import SlackConversation - from slack.slack_workspace import SlackApi, SlackWorkspace + from slack.slack_workspace import SlackWorkspace class SlackMessage: def __init__(self, conversation: SlackConversation, message_json: SlackMessageDict): + self._message_json = message_json self.conversation = conversation self.ts = message_json["ts"] - self.message_json = message_json @property def workspace(self) -> SlackWorkspace: return self.conversation.workspace - @property - def api(self) -> SlackApi: - return self.workspace.api - async def render_message(self): - message = await self.unfurl_refs(self.message_json["text"]) - if "user" in self.message_json: - user = await self.workspace.users[self.message_json["user"]] - prefix = user.name + message = await self._unfurl_refs(self._message_json["text"]) + if "user" in self._message_json: + user = await self.workspace.users[self._message_json["user"]] + prefix = user.nick else: prefix = "bot" return f"{prefix}\t{message}" - async def unfurl_refs(self, message: str): + async def _unfurl_refs(self, message: str): re_user = re.compile("<@([^>]+)>") user_ids: List[str] = re_user.findall(message) users_list = await gather( @@ -45,6 +41,6 @@ class SlackMessage: users = dict(zip(user_ids, users_list)) def unfurl_user(user_id: str): - return "@" + users[user_id].name + return "@" + users[user_id].nick return re_user.sub(lambda match: unfurl_user(match.group(1)), message) |