aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2024-02-19 20:27:51 +0100
committerTrygve Aaberge <trygveaa@gmail.com>2024-02-20 13:21:38 +0100
commitb9e67bba4d4021f3400275c033b42fa8ffd1a476 (patch)
treeb088101e7f070aee00fb926c8dc2a102dcd73bd8
parent6e7ca7290d4a59398438e14623d9e71db7c7508d (diff)
downloadwee-slack-b9e67bba4d4021f3400275c033b42fa8ffd1a476.tar.gz
Make api accessible from SlackBuffer
-rw-r--r--slack/commands.py10
-rw-r--r--slack/completions.py2
-rw-r--r--slack/slack_buffer.py10
-rw-r--r--slack/slack_conversation.py20
-rw-r--r--slack/slack_thread.py2
5 files changed, 22 insertions, 22 deletions
diff --git a/slack/commands.py b/slack/commands.py
index 849a346..52a3e03 100644
--- a/slack/commands.py
+++ b/slack/commands.py
@@ -374,7 +374,7 @@ def get_conversation_from_args(buffer: str, args: List[str], options: Options):
async def command_slack_join(buffer: str, args: List[str], options: Options):
conversation = get_conversation_from_args(buffer, args, options)
if conversation is not None:
- await conversation.workspace.api.conversations_join(conversation.id)
+ await conversation.api.conversations_join(conversation.id)
await conversation.open_buffer(switch=not options.get("noswitch"))
@@ -420,7 +420,7 @@ async def command_slack_presence(buffer: str, args: List[str], options: Options)
f'Error with command "/slack presence {args[0]}" (help on command: /help slack presence)'
)
return
- await slack_buffer.workspace.api.set_presence(new_presence)
+ await slack_buffer.api.set_presence(new_presence)
@weechat_command("list")
@@ -445,7 +445,7 @@ async def command_slack_mute(buffer: str, args: List[str], options: Options):
muted_channels = set(slack_buffer.workspace.muted_channels)
muted_channels ^= {slack_buffer.id}
- await slack_buffer.workspace.api.set_muted_channels(muted_channels)
+ await slack_buffer.api.set_muted_channels(muted_channels)
muted_str = "Muted" if slack_buffer.id in muted_channels else "Unmuted"
weechat.prnt(
"",
@@ -524,9 +524,9 @@ async def command_slack_status(buffer: str, args: List[str], options: Options):
slack_buffer = shared.buffers.get(buffer)
if slack_buffer is not None:
if options.get("clear"):
- await slack_buffer.workspace.api.clear_user_status()
+ await slack_buffer.api.clear_user_status()
elif slack_buffer and len(status) > 0:
- await slack_buffer.workspace.api.set_user_status(status)
+ await slack_buffer.api.set_user_status(status)
else:
print_error(
'Too few arguments for command "/slack status" (help on command: /help slack status)'
diff --git a/slack/completions.py b/slack/completions.py
index 93d4c78..9d279e9 100644
--- a/slack/completions.py
+++ b/slack/completions.py
@@ -252,7 +252,7 @@ async def complete_user_next(
):
if slack_buffer.completion_context == "NO_COMPLETION":
slack_buffer.completion_context = "PENDING_COMPLETION"
- search = await slack_buffer.workspace.api.edgeapi.fetch_users_search(query)
+ search = await slack_buffer.api.edgeapi.fetch_users_search(query)
if slack_buffer.completion_context != "PENDING_COMPLETION":
return
slack_buffer.completion_context = "ACTIVE_COMPLETION"
diff --git a/slack/slack_buffer.py b/slack/slack_buffer.py
index 65f2295..edb1815 100644
--- a/slack/slack_buffer.py
+++ b/slack/slack_buffer.py
@@ -170,7 +170,7 @@ class SlackBuffer(ABC):
self.completion_index = 0
@property
- def _api(self) -> SlackApi:
+ def api(self) -> SlackApi:
return self.workspace.api
@contextmanager
@@ -444,7 +444,7 @@ class SlackBuffer(ABC):
broadcast: bool = False,
):
linkified_text = await self.linkify_text(text)
- await self._api.chat_post_message(
+ await self.api.chat_post_message(
self.conversation, linkified_text, thread_ts, broadcast
)
@@ -453,13 +453,13 @@ class SlackBuffer(ABC):
) -> None:
emoji = shared.standard_emojis_inverse.get(emoji_char)
emoji_name = emoji["name"] if emoji else emoji_char
- await self._api.reactions_change(self.conversation, ts, emoji_name, change_type)
+ await self.api.reactions_change(self.conversation, ts, emoji_name, change_type)
async def edit_message(self, ts: SlackTs, old: str, new: str, flags: str):
message = self.messages[ts]
if new == "" and old == "":
- await self._api.chat_delete_message(self.conversation, message.ts)
+ await self.api.chat_delete_message(self.conversation, message.ts)
else:
num_replace = 0 if "g" in flags else 1
f = re.UNICODE
@@ -469,7 +469,7 @@ class SlackBuffer(ABC):
old_message_text = message.text
new_message_text = re.sub(old, new, old_message_text, num_replace, f)
if new_message_text != old_message_text:
- await self._api.chat_update_message(
+ await self.api.chat_update_message(
self.conversation, message.ts, new_message_text
)
else:
diff --git a/slack/slack_conversation.py b/slack/slack_conversation.py
index 9085397..6cc58f7 100644
--- a/slack/slack_conversation.py
+++ b/slack/slack_conversation.py
@@ -369,7 +369,7 @@ class SlackConversation(SlackBuffer):
async def load_members(self, load_all: bool = False):
if self._members is None:
- members_response = await self._api.fetch_conversations_members(
+ members_response = await self.api.fetch_conversations_members(
self, limit=None if load_all else 1000
)
self._members = members_response["members"]
@@ -377,7 +377,7 @@ class SlackConversation(SlackBuffer):
return self._members
async def fetch_replies(self, thread_ts: SlackTs) -> List[SlackMessage]:
- replies_response = await self._api.fetch_conversations_replies(self, thread_ts)
+ replies_response = await self.api.fetch_conversations_replies(self, thread_ts)
messages = [
SlackMessage(self, message) for message in replies_response["messages"]
]
@@ -419,11 +419,11 @@ class SlackConversation(SlackBuffer):
if self.display_thread_replies()
else self.last_printed_ts
)
- history = await self._api.fetch_conversations_history_after(
+ history = await self.api.fetch_conversations_history_after(
self, history_after_ts
)
else:
- history = await self._api.fetch_conversations_history(self)
+ history = await self.api.fetch_conversations_history(self)
if self.buffer_pointer and shared.current_buffer_pointer != self.buffer_pointer:
for message_json in history["messages"]:
@@ -472,11 +472,11 @@ class SlackConversation(SlackBuffer):
else self.last_printed_ts
)
if history_after_ts:
- history = await self._api.fetch_conversations_history_after(
+ history = await self.api.fetch_conversations_history_after(
self, history_after_ts
)
else:
- history = await self._api.fetch_conversations_history(self)
+ history = await self.api.fetch_conversations_history(self)
conversation_messages = [
SlackMessage(self, message) for message in history["messages"]
@@ -739,11 +739,11 @@ class SlackConversation(SlackBuffer):
return
last_read_line_ts = self.last_read_line_ts()
if last_read_line_ts and last_read_line_ts != self.last_read:
- await self._api.conversations_mark(self, last_read_line_ts)
+ await self.api.conversations_mark(self, last_read_line_ts)
async def part(self):
self._is_joined = False
- await self._api.conversations_leave(self)
+ await self.api.conversations_leave(self)
if shared.config.look.part_closes_buffer.value:
await self.close_buffer()
else:
@@ -763,9 +763,9 @@ class SlackConversation(SlackBuffer):
if update_server:
if self.type in ["im", "mpim"]:
- await self._api.conversations_close(self)
+ await self.api.conversations_close(self)
else:
- await self._api.conversations_leave(self)
+ await self.api.conversations_leave(self)
_T = TypeVar("_T", bound=SlackConversation)
diff --git a/slack/slack_thread.py b/slack/slack_thread.py
index 5e6a8bb..47a00c2 100644
--- a/slack/slack_thread.py
+++ b/slack/slack_thread.py
@@ -136,7 +136,7 @@ class SlackThread(SlackBuffer):
last_read_line_ts = self.last_read_line_ts()
if last_read_line_ts and last_read_line_ts != self.last_read:
- await self._api.subscriptions_thread_mark(
+ await self.api.subscriptions_thread_mark(
self.parent.conversation, self.parent.ts, last_read_line_ts
)