aboutsummaryrefslogtreecommitdiffstats
path: root/slack
diff options
context:
space:
mode:
Diffstat (limited to 'slack')
-rw-r--r--slack/commands.py17
-rw-r--r--slack/slack_api.py30
2 files changed, 45 insertions, 2 deletions
diff --git a/slack/commands.py b/slack/commands.py
index da53244..48f7b23 100644
--- a/slack/commands.py
+++ b/slack/commands.py
@@ -366,6 +366,23 @@ def command_slack_debug(buffer: str, args: List[str], options: Options):
print_uncaught_error(error, True, options)
+@weechat_command("-clean")
+def command_slack_status(buffer: str, args: List[str], options: Options):
+ status = args[0]
+ slack_buffer = shared.buffers.get(buffer)
+ if slack_buffer is not None:
+ if options.get("clean"):
+ run_async(slack_buffer.workspace.api.clear_user_status())
+ elif slack_buffer and len(status) > 0:
+ run_async(slack_buffer.workspace.api.set_user_status(status))
+ else:
+ print_error(
+ 'Too few arguments for command "/slack status" (help on command: /help slack status)'
+ )
+ else:
+ print_error("Run the command in a slack buffer")
+
+
def completion_slack_workspaces_cb(
data: str, completion_item: str, buffer: str, completion: str
) -> int:
diff --git a/slack/slack_api.py b/slack/slack_api.py
index e71860b..83e8962 100644
--- a/slack/slack_api.py
+++ b/slack/slack_api.py
@@ -2,7 +2,14 @@ from __future__ import annotations
import json
from itertools import chain
-from typing import TYPE_CHECKING, Iterable, Mapping, Optional, Sequence, Union
+from typing import (
+ TYPE_CHECKING,
+ Iterable,
+ Mapping,
+ Optional,
+ Sequence,
+ Union,
+)
from urllib.parse import urlencode
from slack.error import SlackApiError
@@ -26,7 +33,12 @@ if TYPE_CHECKING:
from slack_api.slack_team_info import SlackTeamInfoResponse
from slack_api.slack_usergroups_info import SlackUsergroupsInfoResponse
from slack_api.slack_users_conversations import SlackUsersConversationsResponse
- from slack_api.slack_users_info import SlackUserInfoResponse, SlackUsersInfoResponse
+ from slack_api.slack_users_info import (
+ SlackProfile,
+ SlackSetProfile,
+ SlackUserInfoResponse,
+ SlackUsersInfoResponse,
+ )
from slack_api.slack_users_prefs import SlackUsersPrefsGetResponse
from slack_edgeapi.slack_usergroups_info import SlackEdgeUsergroupsInfoResponse
from slack_edgeapi.slack_users_search import SlackUsersSearchResponse
@@ -242,6 +254,20 @@ class SlackApi(SlackApiCommon):
raise SlackApiError(self.workspace, method, response, params)
return response
+ async def _set_user_profile(self, profile: SlackSetProfile):
+ method = "users.profile.set"
+ params: Params = {"profile": dict(profile)}
+ response: SlackProfile = await self._fetch(method, params)
+ if response["ok"] is False:
+ raise SlackApiError(self.workspace, method, response, params)
+ return response
+
+ async def set_user_status(self, status: str):
+ return await self._set_user_profile({"status_text": status})
+
+ async def clear_user_status(self):
+ return await self._set_user_profile({"status_emoji": "", "status_text": ""})
+
async def _fetch_users_info_without_splitting(self, user_ids: Iterable[str]):
method = "users.info"
params: Params = {"users": ",".join(user_ids)}