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.py20
-rw-r--r--slack/slack_user.py11
3 files changed, 18 insertions, 19 deletions
diff --git a/slack/slack_conversation.py b/slack/slack_conversation.py
index ebfc859..9ab254d 100644
--- a/slack/slack_conversation.py
+++ b/slack/slack_conversation.py
@@ -43,7 +43,7 @@ class SlackConversation:
self.history_pending = False
@property
- def api(self) -> SlackApi:
+ def _api(self) -> SlackApi:
return self.workspace.api
@contextmanager
@@ -58,7 +58,7 @@ class SlackConversation:
async def init(self):
with self.loading():
- info = await self.api.fetch_conversations_info(self)
+ info = await self._api.fetch_conversations_info(self)
if info["ok"] is False:
# TODO: Handle error
raise Exception("Failed fetching conversation info")
@@ -83,7 +83,7 @@ class SlackConversation:
with self.loading():
self.history_pending = True
- history = await self.api.fetch_conversations_history(self)
+ history = await self._api.fetch_conversations_history(self)
if history["ok"] is False:
# TODO: Handle error
raise Exception("Failed fetching conversation history")
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)
diff --git a/slack/slack_user.py b/slack/slack_user.py
index 4386657..8fcd445 100644
--- a/slack/slack_user.py
+++ b/slack/slack_user.py
@@ -10,15 +10,18 @@ class SlackUser:
def __init__(self, workspace: SlackWorkspace, id: str):
self.workspace = workspace
self.id = id
- self.name: str
@property
- def api(self) -> SlackApi:
+ def _api(self) -> SlackApi:
return self.workspace.api
+ @property
+ def nick(self):
+ return self._info["name"]
+
async def init(self):
- info = await self.api.fetch_users_info(self)
+ info = await self._api.fetch_users_info(self)
if info["ok"] is False:
# TODO: Handle error
raise Exception("Failed fetching user info")
- self.name = info["user"]["name"]
+ self._info = info["user"]