diff options
Diffstat (limited to 'wee_slack.py')
-rw-r--r-- | wee_slack.py | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/wee_slack.py b/wee_slack.py index bbfe9c8..47b9ad7 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -610,15 +610,17 @@ def buffer_input_callback(signal, buffer_ptr, data): eventrouter = eval(signal) channel = eventrouter.weechat_controller.get_channel_from_buffer_ptr(buffer_ptr) if not channel: - return w.WEECHAT_RC_OK_EAT + return w.WEECHAT_RC_ERROR reaction = re.match("^\s*(\d*)(\+|-):(.*):\s*$", data) + substitute = re.match("^(\d*)s/", data) if reaction: if reaction.group(2) == "+": channel.send_add_reaction(int(reaction.group(1) or 1), reaction.group(3)) elif reaction.group(2) == "-": channel.send_remove_reaction(int(reaction.group(1) or 1), reaction.group(3)) - elif data.startswith('s/'): + elif substitute: + msgno = int(substitute.group(1) or 1) try: old, new, flags = re.split(r'(?<!\\)/', data)[1:] except ValueError: @@ -628,11 +630,11 @@ def buffer_input_callback(signal, buffer_ptr, data): # rid of escapes. new = new.replace(r'\/', '/') old = old.replace(r'\/', '/') - channel.edit_previous_message(old, new, flags) + channel.edit_nth_previous_message(msgno, old, new, flags) else: channel.send_message(data) # this is probably wrong channel.mark_read(update_remote=True, force=True) - return w.WEECHAT_RC_ERROR + return w.WEECHAT_RC_OK def buffer_switch_callback(signal, sig_type, data): @@ -1141,7 +1143,7 @@ class SlackChannel(object): def set_unread_count_display(self, count): self.unread_count_display = count - if (self.unread_count_display > 0): + for c in range(self.unread_count_display): if self.type == "im": w.buffer_set(self.channel_buffer, "hotlist", "2") else: @@ -1337,8 +1339,8 @@ class SlackChannel(object): modify_buffer_line(self.channel_buffer, text, ts.major, ts.minor) return True - def edit_previous_message(self, old, new, flags): - message = self.my_last_message() + def edit_nth_previous_message(self, n, old, new, flags): + message = self.my_last_message(n) if new == "" and old == "": s = SlackRequest(self.team.token, "chat.delete", {"channel": self.identifier, "ts": message['ts']}, team_hash=self.team.team_hash, channel_identifier=self.identifier) self.eventrouter.receive(s) @@ -1351,11 +1353,13 @@ class SlackChannel(object): s = SlackRequest(self.team.token, "chat.update", {"channel": self.identifier, "ts": message['ts'], "text": new_message}, team_hash=self.team.team_hash, channel_identifier=self.identifier) self.eventrouter.receive(s) - def my_last_message(self): + def my_last_message(self, msgno): for message in reversed(self.sorted_message_keys()): m = self.messages[message] if "user" in m.message_json and "text" in m.message_json and m.message_json["user"] == self.team.myidentifier: - return m.message_json + msgno -= 1 + if msgno == 0: + return m.message_json def is_visible(self): return w.buffer_get_integer(self.channel_buffer, "hidden") == 0 @@ -1768,7 +1772,7 @@ class SlackThreadChannel(object): self.channel_buffer = w.buffer_new(self.formatted_name(style="long_default"), "buffer_input_callback", "EVENTROUTER", "", "") self.eventrouter.weechat_controller.register_buffer(self.channel_buffer, self) w.buffer_set(self.channel_buffer, "localvar_set_type", 'channel') - w.buffer_set(self.channel_buffer, "localvar_set_nick", self.team.nick) + w.buffer_set(self.channel_buffer, "localvar_set_nick", self.parent_message.team.nick) w.buffer_set(self.channel_buffer, "localvar_set_channel", self.formatted_name()) w.buffer_set(self.channel_buffer, "short_name", self.formatted_name(style="sidebar", enable_color=True)) time_format = w.config_string(w.config_get("weechat.look.buffer_time_format")) @@ -2520,9 +2524,16 @@ def linkify_text(message, team, channel): usernames = team.get_username_map() channels = team.get_channel_map() message = (message + # Replace IRC formatting chars with Slack formatting chars. .replace('\x02', '*') .replace('\x1D', '_') .replace('\x1F', config.map_underline_to) + # Escape chars that have special meaning to Slack. Note that we do not + # (and should not) perform a full URL escaping here. + # See https://api.slack.com/docs/message-formatting for details. + .replace('<', '<') + .replace('>', '>') + .replace('&', '&') .split(' ')) for item in enumerate(message): targets = re.match('^\s*([@#])([\w.-]+[\w. -])(\W*)', item[1]) |