diff --git a/matrix/commands.py b/matrix/commands.py index a601602..c7ae56f 100644 --- a/matrix/commands.py +++ b/matrix/commands.py @@ -91,23 +91,23 @@ def hook_commands(): 'matrix_command_cb', '') - # W.hook_command( - # # Command name and short description - # 'redact', - # 'redact messages', - # # Synopsis - # ('[:""] []'), - # # 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 + ('[:""] []'), + # 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,13 +434,14 @@ 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)" - ).format(prefix=W.prefix("error")) + 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 diff --git a/matrix/server.py b/matrix/server.py index 6aaff99..3db149b 100644 --- a/matrix/server.py +++ b/matrix/server.py @@ -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):