From 199e6de2a7269d597a13ee0ae0286c9489cc9307 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Thu, 29 Nov 2018 17:09:21 +0100 Subject: [PATCH] commands: Add initial room command. --- main.py | 3 ++- matrix/commands.py | 61 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index e2501e7..2cd7bd3 100644 --- a/main.py +++ b/main.py @@ -52,7 +52,8 @@ from matrix.commands import (hook_commands, hook_page_up, matrix_join_command_cb, matrix_kick_command_cb, matrix_me_command_cb, matrix_part_command_cb, matrix_redact_command_cb, matrix_topic_command_cb, - matrix_olm_command_cb, matrix_devices_command_cb) + matrix_olm_command_cb, matrix_devices_command_cb, + matrix_room_command_cb) from matrix.completion import (init_completion, matrix_command_completion_cb, matrix_debug_completion_cb, matrix_message_completion_cb, diff --git a/matrix/commands.py b/matrix/commands.py index 7ab5edf..9350b67 100644 --- a/matrix/commands.py +++ b/matrix/commands.py @@ -141,6 +141,18 @@ class WeechatCommandParser(object): return WeechatCommandParser._run_parser(parser, args) + @staticmethod + def room(args): + parser = WeechatArgParse(prog="room") + subparsers = parser.add_subparsers(dest="subcommand") + typing_notification = subparsers.add_parser("typing-notifications") + typing_notification.add_argument( + "state", + choices=["enable", "disable", "toggle"] + ) + + return WeechatCommandParser._run_parser(parser, args) + def grouper(iterable, n, fillvalue=None): "Collect data into fixed-length chunks or blocks" @@ -359,6 +371,22 @@ def hook_commands(): 'matrix_olm_command_cb', '') + W.hook_command( + # Command name and short description + "room", + "change room state", + # Synopsis + ("typing-notifications " + ), + # Description + ("state: one of enable, disable or toggle\n"), + # Completions + ("typing-notifications enable|disable|toggle"), + # Callback + "matrix_room_command_cb", + "", + ) + W.hook_command_run("/buffer clear", "matrix_command_buf_clear_cb", "") if G.CONFIG.network.fetch_backlog_on_pgup: @@ -857,6 +885,39 @@ def matrix_invite_command_cb(data, buffer, args): return W.WEECHAT_RC_OK +@utf8_decode +def matrix_room_command_cb(data, buffer, args): + parsed_args = WeechatCommandParser.room(args) + if not parsed_args: + return W.WEECHAT_RC_OK + + for server in SERVERS.values(): + if buffer == server.server_buffer: + server.error( + 'command "room" must be ' "executed on a Matrix room buffer" + ) + return W.WEECHAT_RC_OK + + room = server.find_room_from_ptr(buffer) + if not room: + continue + + if not parsed_args.subcommand or parsed_args.subcommand == "list": + server.error("command no subcommand found") + return W.WEECHAT_RC_OK + + if parsed_args.subcommand == "typing-notifications": + if parsed_args.state == "enable": + room.typing_enabled = True + elif parsed_args.state == "disable": + room.typing_enabled = False + elif parsed_args.state == "toggle": + room.typing_enabled = not room.typing_enabled + break + + return W.WEECHAT_RC_OK + + @utf8_decode def matrix_kick_command_cb(data, buffer, args): parsed_args = WeechatCommandParser.kick(args)