commands: Add redaction support back.

This commit is contained in:
Damir Jelić 2018-08-22 11:37:33 +02:00
parent 166ff3b2e3
commit 607aad655b
2 changed files with 29 additions and 24 deletions

View file

@ -91,23 +91,23 @@ def hook_commands():
'matrix_command_cb',
'')
# W.hook_command(
# # Command name and short description
# 'redact',
# 'redact messages',
# # Synopsis
# ('<message-number>[:"<message-part>"] [<reason>]'),
# # Description
# ("message-number: number of message to redact (starting from 1 for\n"
# " the last message received, counting up)\n"
# " message-part: an initial part of the message (ignored, only used\n"
# " as visual feedback when using completion)\n"
# " reason: the redaction reason\n"),
# # Completions
# ('%(matrix_messages)'),
# # Function name
# 'matrix_redact_command_cb',
# '')
W.hook_command(
# Command name and short description
'redact',
'redact messages',
# Synopsis
('<message-number>[:"<message-part>"] [<reason>]'),
# Description
("message-number: number of message to redact (starting from 1 for\n"
" the last message received, counting up)\n"
" message-part: an initial part of the message (ignored, only used\n"
" as visual feedback when using completion)\n"
" reason: the redaction reason\n"),
# Completions
('%(matrix_messages)'),
# Function name
'matrix_redact_command_cb',
'')
W.hook_command(
# Command name and short description
@ -434,12 +434,13 @@ def event_id_from_line(buf, target_number):
def matrix_redact_command_cb(data, buffer, args):
for server in SERVERS.values():
if buffer in server.buffers.values():
room_id = key_from_value(server.buffers, buffer)
room_buffer = server.find_room_from_ptr(buffer)
matches = re.match(r"(\d+)(:\".*\")? ?(.*)?", args)
if not matches:
message = ("{prefix}matrix: Invalid command arguments (see /help redact)"
message = ("{prefix}matrix: Invalid command "
"arguments (see /help redact)"
).format(prefix=W.prefix("error"))
W.prnt("", message)
return W.WEECHAT_RC_ERROR
@ -456,7 +457,7 @@ def matrix_redact_command_cb(data, buffer, args):
W.prnt("", message)
return W.WEECHAT_RC_OK
raise NotImplementedError
server.room_send_redaction(room_buffer, event_id, reason)
return W.WEECHAT_RC_OK

View file

@ -508,6 +508,13 @@ class MatrixServer(object):
)
self.send_or_queue(request)
def room_send_redaction(self, room_buffer, event_id, reason=None):
_, request = self.client.room_redact(
room_buffer.room.room_id,
event_id,
reason)
self.send_or_queue(request)
def room_send_message(self, room_buffer, formatted, msgtype="m.text"):
# type: (RoomBuffer, Formatted, str) -> None
if room_buffer.room.encrypted:
@ -654,9 +661,6 @@ class MatrixServer(object):
elif isinstance(response, RoomSendResponse):
self.handle_own_messages(response)
elif isinstance(response, RoomPutStateResponse):
pass
return
def create_room_buffer(self, room_id):