commands: Add initial room command.
This commit is contained in:
parent
66765f96d8
commit
199e6de2a7
2 changed files with 63 additions and 1 deletions
3
main.py
3
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,
|
||||
|
|
|
@ -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 <state>"
|
||||
),
|
||||
# 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)
|
||||
|
|
Loading…
Reference in a new issue