From e9b82a56f5a81968cd22c12241327c1165589634 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Thu, 27 Jun 2019 11:48:28 +0200 Subject: [PATCH] commands: Add a send-anyways command. --- main.py | 2 +- matrix/commands.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 93a04df..db71a70 100644 --- a/main.py +++ b/main.py @@ -54,7 +54,7 @@ from matrix.commands import (hook_commands, hook_page_up, matrix_redact_command_cb, matrix_topic_command_cb, matrix_olm_command_cb, matrix_devices_command_cb, matrix_room_command_cb, matrix_uploads_command_cb, - matrix_upload_command_cb) + matrix_upload_command_cb, matrix_send_anyways_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 bcdc204..ca80d24 100644 --- a/matrix/commands.py +++ b/matrix/commands.py @@ -480,6 +480,23 @@ def hook_commands(): "", ) + W.hook_command( + # Command name and short description + "send-anyways", + "Send the last message in a room ignorin unverified devices.", + # Synopsis + "", + # Description + "Send the last message in a room despite there being unverified " + "devices. The unverified devices will be marked as ignored after " + "running this command.", + # Completions + "", + # Callback + "matrix_send_anyways_cb", + "", + ) + W.hook_command_run("/buffer clear", "matrix_command_buf_clear_cb", "") if G.CONFIG.network.fetch_backlog_on_pgup: @@ -1735,3 +1752,36 @@ def matrix_command_cb(data, buffer, args): W.prnt("", message) return W.WEECHAT_RC_OK + + +@utf8_decode +def matrix_send_anyways_cb(data, buffer, args): + for server in SERVERS.values(): + if buffer in server.buffers.values(): + room_buffer = server.find_room_from_ptr(buffer) + + if not server.connected: + room_buffer.error("Server is diconnected") + break + + if not room_buffer.last_message: + room_buffer.error("No previously sent message found.") + break + + server.room_send_message( + room_buffer, + room_buffer.last_message, + "m.text", + ignore_unverified_devices=True + ) + room_buffer.last_message = None + + break + else: + message = ( + "{prefix}matrix: The 'send-anyways' command needs to be " + "run on a matrix room buffer" + ).format(prefix=W.prefix("error")) + W.prnt("", message) + + return W.WEECHAT_RC_ERROR