diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2017-09-03 16:56:45 +0200 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2017-09-05 17:04:08 +0200 |
commit | 4bf54a67516059b352789dc40127d099a06ffd3a (patch) | |
tree | d9f98c2151d30496a8e819c39b098fbc0a63aa60 /wee_slack.py | |
parent | 5608e22cdeb9ba3a07e2925fc97bb47bcbbc17da (diff) | |
download | wee-slack-4bf54a67516059b352789dc40127d099a06ffd3a.tar.gz |
Add support for sending multiline messages
While weechat plugins like multiline.pl and edit.py allow you to compose
multiline messages, wee-slack normally receives them line by line, so it
ends up as separate messages. There isn't any direct support for
receiving the complete message from weechat, but it can be done with
sort of a workaround.
There is a callback you can hook on to which allows you to intercept and
edit messages before they are sent to the buffer. This callback receives
the complete message with all the lines. By using this we can process
the whole message, and return an empty string from the callback which
means that the message will not be processed further.
Note that when this happens, weechat commands are not processed, which
is why we only use the callback for messages that contain a newline and
does not start with slash. Otherwise, we are returning the string sent
to the callback, which would be the same as the callback not being
hooked in.
I've also opened a PR in weechat for supporting multiline input
properly[0]. If that is merged, that can be used for newer weechat
versions instead of this.
[0]: https://github.com/weechat/weechat/pull/1063
Fixes #118
Diffstat (limited to 'wee_slack.py')
-rw-r--r-- | wee_slack.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/wee_slack.py b/wee_slack.py index 3904ab0..2daeda2 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -637,6 +637,19 @@ def buffer_input_callback(signal, buffer_ptr, data): return w.WEECHAT_RC_OK +# Workaround for supporting multiline messages. It intercepts before the input +# callback is called, as this is called with the whole message, while it is +# normally split on newline before being sent to buffer_input_callback +def input_text_for_buffer_cb(data, modifier, current_buffer, string): + if current_buffer not in EVENTROUTER.weechat_controller.buffers: + return string + message = decode_from_utf8(string) + if "\n" in message and not message.startswith("/"): + buffer_input_callback("EVENTROUTER", current_buffer, message) + return "" + return string + + def buffer_switch_callback(signal, sig_type, data): """ incomplete @@ -3565,6 +3578,7 @@ if __name__ == "__main__": # main_weechat_buffer = w.info_get("irc_buffer", "{}.{}".format(domain, "DOESNOTEXIST!@#$")) w.hook_config("plugins.var.python." + SCRIPT_NAME + ".*", "config_changed_cb", "") + w.hook_modifier("input_text_for_buffer", "input_text_for_buffer_cb", "") load_emoji() setup_hooks() |