diff options
author | Pier <pierg75@yahoo.it> | 2024-02-18 10:54:01 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-18 11:54:01 +0100 |
commit | 0531090db0976b1261a033dd2eabd4c641a91d2c (patch) | |
tree | 270a8a13c683260d81a7b27f17f7a61068be59aa | |
parent | 1989a394e96df843a1e5d852e9706cafcf6c0945 (diff) | |
download | wee-slack-0531090db0976b1261a033dd2eabd4c641a91d2c.tar.gz |
Set user user presence (#919)
The user can now set the presence with:
/slack presence away
Or:
/slack presence active
Signed-off-by: Pierguido Lambri <plambri@redhat.com>
-rw-r--r-- | slack/commands.py | 14 | ||||
-rw-r--r-- | slack/slack_api.py | 8 |
2 files changed, 22 insertions, 0 deletions
diff --git a/slack/commands.py b/slack/commands.py index a866894..da53244 100644 --- a/slack/commands.py +++ b/slack/commands.py @@ -287,6 +287,20 @@ def command_slack_reply(buffer: str, args: List[str], options: Options): run_async(slack_buffer.post_message(split_args[1], thread_ts, broadcast)) +@weechat_command("away|active") +def command_slack_presence(buffer: str, args: List[str], options: Options): + slack_buffer = shared.buffers.get(buffer) + if slack_buffer is None: + return + new_presence = args[0] + if new_presence not in ("active", "away"): + print_error( + f'Error with command "/slack presence {args[0]}" (help on command: /help slack presence)' + ) + return + run_async(slack_buffer.workspace.api.set_presence(new_presence)) + + def print_uncaught_error(error: UncaughtError, detailed: bool, options: Options): weechat.prnt("", f" {error.id} ({error.time}): {error.exception}") if detailed: diff --git a/slack/slack_api.py b/slack/slack_api.py index 2f57e61..e71860b 100644 --- a/slack/slack_api.py +++ b/slack/slack_api.py @@ -412,3 +412,11 @@ class SlackApi(SlackApiCommon): if response["ok"] is False: raise SlackApiError(self.workspace, method, response, params) return response + + async def set_presence(self, presence: Literal["active", "away"]): + method = "presence.set" + params: Params = {"presence": presence} + response: SlackGenericResponse = await self._fetch(method, params) + if response["ok"] is False: + raise SlackApiError(self.workspace, method, response, params) + return response |