Last active
July 2, 2020 13:07
-
-
Save tomsmeding/25a8f2f9004ef4ae0ad739bb01aadf0b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import weechat | |
import re | |
weechat.register( | |
"matrix-reply", | |
"Tom Smeding", | |
"0.1", | |
"MIT", | |
"Reply helper for weechat-matrix buffers", | |
"shutdown_cb", | |
"" | |
) | |
def shutdown_cb(): | |
weechat.key_unbind("cursor", "@chat:r") | |
return weechat.WEECHAT_RC_OK | |
def cursor_signal_cb(_data, signal, ht): | |
tags = ht["_chat_line_tags"].split(",") | |
weechat.command("", "/cursor stop") | |
if "matrix_message" in tags: | |
for tag in tags: | |
if tag.startswith("matrix_id_"): | |
matrix_id = tag[10:] | |
break | |
else: | |
return weechat.WEECHAT_RC_OK | |
buffer_name = ht["_buffer_full_name"] | |
bufptr = weechat.buffer_search("==", buffer_name) | |
current_input = weechat.buffer_get_string(bufptr, "input") | |
input_pos = weechat.buffer_get_integer(bufptr, "input_pos") | |
new_prefix = "/reply-matrix {} ".format(matrix_id) | |
weechat.buffer_set(bufptr, "input", new_prefix + current_input) | |
weechat.buffer_set(bufptr, "input_pos", str(len(new_prefix) + input_pos)) | |
return weechat.WEECHAT_RC_OK | |
weechat.hook_hsignal("matrix_cursor_reply", "cursor_signal_cb", "") | |
weechat.key_bind("cursor", {"@chat:r": "hsignal:matrix_cursor_reply"}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment