aboutsummaryrefslogtreecommitdiffstats
path: root/slack
diff options
context:
space:
mode:
authorPierguido Lambri <plambri@redhat.com>2024-01-13 18:35:36 +0000
committerTrygve Aaberge <trygveaa@gmail.com>2024-02-18 12:55:39 +0100
commit3b6bc38b53ca9ea81c8a055c78b9d93f0d75768b (patch)
treeaed4439a3491bca17c18174c1f5e5b2c1b639552 /slack
parent0531090db0976b1261a033dd2eabd4c641a91d2c (diff)
downloadwee-slack-3b6bc38b53ca9ea81c8a055c78b9d93f0d75768b.tar.gz
Set user status
It's now possible to set and clear the uses status. For now it's not possible to set the status emoji or the status expiration. Signed-off-by: Pierguido Lambri <plambri@redhat.com>
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)}