diff options
Diffstat (limited to 'slack')
-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 |