diff options
author | Ryan Huber <rhuber@gmail.com> | 2015-02-20 12:36:54 -0800 |
---|---|---|
committer | Ryan Huber <rhuber@gmail.com> | 2015-02-20 12:36:54 -0800 |
commit | c27acb3b432cfb6fc30b10871b378c044ab24b3c (patch) | |
tree | b790beaafed45a21a7623818c09ecc20af426d63 | |
parent | f04f94c81c2664b61ae755e6567ac60c82393910 (diff) | |
download | wee-slack-c27acb3b432cfb6fc30b10871b378c044ab24b3c.tar.gz |
regex style message editing
-rw-r--r-- | README.md | 7 | ||||
-rw-r--r-- | wee_slack.py | 26 |
2 files changed, 26 insertions, 7 deletions
@@ -14,9 +14,10 @@ A WeeChat native client for Slack.com. Provides supplemental features only avail Features -------- - * **New** Caches message history, making startup MUCH faster - * **New** Smarter redraw of dynamic buffer info (much lower CPU %) - * **New** beta UTF-8 support + * **New** regex style message editing (s/oldtext/newtext/) + * Caches message history, making startup MUCH faster + * Smarter redraw of dynamic buffer info (much lower CPU %) + * beta UTF-8 support * Doesn't use IRC gateway. Connects directly with Slack via API/Websocket * Multiple Teams supported! Just add multiple api tokens separated by commas * Replays history automatically during startup. (and sets read marker to the correct position in history) diff --git a/wee_slack.py b/wee_slack.py index d437233..bc19bee 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -19,7 +19,7 @@ except: SCRIPT_NAME = "slack_extension" SCRIPT_AUTHOR = "Ryan Huber <rhuber@gmail.com>" -SCRIPT_VERSION = "0.97.16" +SCRIPT_VERSION = "0.97.17" SCRIPT_LICENSE = "MIT" SCRIPT_DESC = "Extends weechat for typing notification/search/etc on slack.com" @@ -335,9 +335,14 @@ class SlackThing(object): def buffer_input_cb(b, buffer, data): - channel = channels.find(buffer) - channel.send_message(data) - channel.buffer_prnt(channel.server.nick, data) + if not data.startswith('s/'): + channel = channels.find(buffer) + channel.send_message(data) + channel.buffer_prnt(channel.server.nick, data) + elif data.count('/') == 3: + old, new = data.split('/')[1:3] + channel = channels.find(buffer) + channel.change_previous_message(old, new) channel.mark_read(True) return w.WEECHAT_RC_ERROR @@ -562,6 +567,19 @@ class Channel(SlackThing): self.last_received = time self.unset_typing(user) + def change_previous_message(self, old, new): + message = self.my_last_message() + if new == "" and old == "": + async_slack_api_request(self.server.domain, self.server.token, 'chat.delete', {"channel": self.identifier, "ts": message['ts']}) + else: + new_message = message["text"].replace(old, new) + async_slack_api_request(self.server.domain, self.server.token, 'chat.update', {"channel": self.identifier, "ts": message['ts'], "text": new_message}) + + def my_last_message(self): + for message in reversed(message_cache[self.identifier]): + if "user" in message and "text" in message and message["user"] == self.server.users.find(self.server.nick).identifier: + return message + def get_history(self): if self.active: if self.identifier in message_cache.keys(): |