From 27144891f1d9280821c5fa99fe4665c2b9b5b682 Mon Sep 17 00:00:00 2001 From: Tollef Fog Heen Date: Sat, 29 Aug 2015 00:39:30 +0200 Subject: Render _foo bar baz_ as action messages The slack client (and we) change `/me foo bar baz` into a `_foo bar baz_` message. Translate those messages back into actions when displaying them. Fixes: #61 --- wee_slack.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/wee_slack.py b/wee_slack.py index eae2e1d..a5b4c9e 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -1428,6 +1428,11 @@ def process_message(message_json, cache=True): channel.buffer_prnt(w.prefix("join").rstrip(), text, time) elif message_json.get("subtype", "") == "channel_topic": channel.buffer_prnt(w.prefix("network").rstrip(), text, time) + elif text.startswith("_") and text.endswith("_"): + text = text[1:-1] + if name != channel.server.nick: + text = name + " " + text + channel.buffer_prnt(w.prefix("action").rstrip(), text, time) else: channel.buffer_prnt(name, text, time) -- cgit From 86d969e763b89a9c4d0e8707ec0767c83822bec5 Mon Sep 17 00:00:00 2001 From: Nate Jones Date: Sun, 29 Mar 2015 16:49:00 -0400 Subject: support server aliases, so buffer names are shorter --- README.md | 5 +++++ wee_slack.py | 17 ++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index fb82724..3c9fe84 100644 --- a/README.md +++ b/README.md @@ -170,6 +170,11 @@ Turn off colorized nicks: /set plugins.var.python.slack_extension.colorize_nicks 0 ``` +Set channel prefix to something other than my-slack-subdomain.slack.com (e.g. when using buffers.pl): +``` +/set plugins.var.python.slack_extension.server_alias.my-slack-subdomain "mysub" +``` + Set all read markers to a specific time: ``` /slack setallreadmarkers (time in epoch) diff --git a/wee_slack.py b/wee_slack.py index eae2e1d..5e7c683 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -120,6 +120,7 @@ class SlackServer(object): self.nick = None self.name = None self.domain = None + self.server_alias = None self.login_data = None self.buffer = None self.token = token @@ -201,6 +202,12 @@ class SlackServer(object): self.domain = login_data["team"]["domain"] + ".slack.com" dbg("connected to {}".format(self.domain)) self.identifier = self.domain + + if not w.config_get_plugin("server_alias.{}".format(login_data["team"]["domain"])): + self.server_alias = login_data["team"]["domain"] + else: + self.server_alias = w.config_get_plugin("server_alias.{}".format(login_data["team"]["domain"])) + self.nick = login_data["self"]["name"] self.create_local_buffer() @@ -242,7 +249,7 @@ class SlackServer(object): def create_local_buffer(self): if not w.buffer_search("", self.domain): - self.buffer = w.buffer_new(self.domain, "buffer_input_cb", "", "", "") + self.buffer = w.buffer_new("{}.server".format(self.server_alias), "buffer_input_cb", "", "", "") w.buffer_set(self.buffer, "nicklist", "1") w.nicklist_add_group(self.buffer, '', NICK_GROUP_HERE, "weechat.color.nicklist_group", 1) @@ -369,11 +376,11 @@ class Channel(object): self.members_table[user] = self.server.users.find(user) def create_buffer(self): - channel_buffer = w.buffer_search("", "{}.{}".format(self.server.domain, self.name)) + channel_buffer = w.buffer_search("", "{}.{}".format(self.server.server_alias, self.name)) if channel_buffer: self.channel_buffer = channel_buffer else: - self.channel_buffer = w.buffer_new("{}.{}".format(self.server.domain, self.name), "buffer_input_cb", self.name, "", "") + self.channel_buffer = w.buffer_new("{}.{}".format(self.server.server_alias, self.name), "buffer_input_cb", self.name, "", "") if self.type == "im": w.buffer_set(self.channel_buffer, "localvar_set_type", 'private') else: @@ -382,7 +389,7 @@ class Channel(object): buffer_list_update_next() def attach_buffer(self): - channel_buffer = w.buffer_search("", "{}.{}".format(self.server.domain, self.name)) + channel_buffer = w.buffer_search("", "{}.{}".format(self.server.server_alias, self.name)) if channel_buffer != main_weechat_buffer: self.channel_buffer = channel_buffer w.buffer_set(self.channel_buffer, "localvar_set_nick", self.server.nick) @@ -417,7 +424,7 @@ class Channel(object): dbg("DEBUG: {} {} {}".format(self.identifier, self.name, e)) def fullname(self): - return "{}.{}".format(self.server.domain, self.name) + return "{}.{}".format(self.server.server_alias, self.name) def has_user(self, name): return name in self.members -- cgit From 103747147001e0351409763ad6a4a84510a810f5 Mon Sep 17 00:00:00 2001 From: Tollef Fog Heen Date: Fri, 25 Sep 2015 04:19:09 +0200 Subject: Avoid putting colors in private chat names Channel names in weechat are simple strings that should not have colors embedded, so don't do that (unless overridden by a configuration setting). In addition, remove channels_not_on_current_server_color support. Fixes #73 --- wee_slack.py | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/wee_slack.py b/wee_slack.py index db4b178..c06fd66 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -531,17 +531,13 @@ class Channel(object): async_slack_api_request(self.server.domain, self.server.token, SLACK_API_TRANSLATOR[self.type]["mark"], {"channel": self.identifier, "ts": time}) def rename(self): - if current_domain_name() != self.server.domain and channels_not_on_current_server_color: - color = w.color(channels_not_on_current_server_color) - else: - color = "" if self.is_someone_typing(): new_name = ">{}".format(self.name[1:]) else: new_name = self.name if self.channel_buffer: - if w.buffer_get_string(self.channel_buffer, "short_name") != (color + new_name): - w.buffer_set(self.channel_buffer, "short_name", color + new_name) + if w.buffer_get_string(self.channel_buffer, "short_name") != new_name: + w.buffer_set(self.channel_buffer, "short_name", new_name) # deprecated in favor of redrawing the entire buffer # def buffer_prnt_changed(self, user, text, time, append=""): @@ -683,15 +679,12 @@ class DmChannel(Channel): self.type = "im" def rename(self): - if current_domain_name() != self.server.domain and channels_not_on_current_server_color: - force_color = w.color(channels_not_on_current_server_color) - else: - force_color = None + global colorize_private_chats if self.server.users.find(self.name).presence == "active": - new_name = self.server.users.find(self.name).formatted_name('+', force_color) + new_name = self.server.users.find(self.name).formatted_name('+', colorize_private_chats) else: - new_name = self.server.users.find(self.name).formatted_name(' ', force_color) + new_name = self.server.users.find(self.name).formatted_name(' ', colorize_private_chats) if self.channel_buffer: w.buffer_set(self.channel_buffer, "short_name", new_name) @@ -766,9 +759,9 @@ class User(object): self.color = "" self.color_name = "" - def formatted_name(self, prepend="", force_color=None): - if colorize_nicks: - print_color = force_color or self.color + def formatted_name(self, prepend="", enable_color=True): + if colorize_nicks and enable_color: + print_color = self.color else: print_color = "" return print_color + prepend + self.name @@ -1847,7 +1840,7 @@ def create_slack_debug_buffer(): def config_changed_cb(data, option, value): - global slack_api_token, distracting_channels, channels_not_on_current_server_color, colorize_nicks, slack_debug, debug_mode, \ + global slack_api_token, distracting_channels, colorize_nicks, colorize_private_chats, slack_debug, debug_mode, \ unfurl_ignore_alt_text slack_api_token = w.config_get_plugin("slack_api_token") @@ -1856,13 +1849,11 @@ def config_changed_cb(data, option, value): slack_api_token = w.string_eval_expression(slack_api_token, {}, {}, {}) distracting_channels = [x.strip() for x in w.config_get_plugin("distracting_channels").split(',')] - channels_not_on_current_server_color = w.config_get_plugin("channels_not_on_current_server_color") - if channels_not_on_current_server_color == "0": - channels_not_on_current_server_color = False colorize_nicks = w.config_get_plugin('colorize_nicks') == "1" debug_mode = w.config_get_plugin("debug_mode").lower() if debug_mode != '' and debug_mode != 'false': create_slack_debug_buffer() + colorize_private_chats = w.config_string_to_boolean(w.config_get_plugin("colorize_private_chats")) unfurl_ignore_alt_text = False if w.config_get_plugin('unfurl_ignore_alt_text') != "0": @@ -1913,12 +1904,12 @@ if __name__ == "__main__": w.config_set_plugin('slack_api_token', "INSERT VALID KEY HERE!") if not w.config_get_plugin('distracting_channels'): w.config_set_plugin('distracting_channels', "") - if not w.config_get_plugin('channels_not_on_current_server_color'): - w.config_set_plugin('channels_not_on_current_server_color', "0") if not w.config_get_plugin('debug_mode'): w.config_set_plugin('debug_mode', "") if not w.config_get_plugin('colorize_nicks'): w.config_set_plugin('colorize_nicks', "1") + if not w.config_get_plugin('colorize_private_chats'): + w.config_set_plugin('colorize_private_chats', "0") if not w.config_get_plugin('trigger_value'): w.config_set_plugin('trigger_value', "0") if not w.config_get_plugin('unfurl_ignore_alt_text'): @@ -1926,6 +1917,8 @@ if __name__ == "__main__": if not w.config_get_plugin('switch_buffer_on_join'): w.config_set_plugin('switch_buffer_on_join', "1") + w.config_option_unset('channels_not_on_current_server_color') + version = w.info_get("version_number", "") or 0 if int(version) >= 0x00040400: legacy_mode = False -- cgit From c79e62cc8f2579fee4f7345dd5b79617d3a5eb6b Mon Sep 17 00:00:00 2001 From: Justin Kenyon Date: Fri, 18 Sep 2015 16:09:15 -0400 Subject: Add upload capability to slack buffer This commit: - Adds the ability to upload a file to the current slack buffer using the `/slack upload [file_path]` command Why? - This is a very useful feature for people that are trying to fully replace the slack web app --- README.md | 8 +++++++- wee_slack.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5442ae7..b3b5aaa 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,8 @@ A WeeChat native client for Slack.com. Provides supplemental features only avail Features -------- - * **New** Emoji reactions! + * **New** Upload to slack capabilities! + * Emoji reactions! * Edited messages work just like the official clients, where the original message changes and has (edited) appended. * Unfurled urls dont generate a new message, but replace the original with more info as it is received. * Regex style message editing (s/oldtext/newtext/) @@ -169,6 +170,11 @@ Set all read markers to a specific time: /slack setallreadmarkers (time in epoch) ``` +Upload a file to the current slack buffer: +``` +/slack upload [file_path] +``` + Debug mode: ``` /slack debug diff --git a/wee_slack.py b/wee_slack.py index c789b43..4b334c0 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -4,6 +4,7 @@ from functools import wraps import time import json +import os import pickle import sha import re @@ -901,6 +902,26 @@ def slack_buffer_required(f): return wrapper +@slack_buffer_required +def command_upload(current_buffer, args): + """ + Uploads a file to the current buffer + /slack upload [file_path] + """ + post_data = {} + channel = current_buffer_name(short=True) + domain = current_domain_name() + token = servers.find(domain).token + + if servers.find(domain).channels.find(channel): + channel_identifier = servers.find(domain).channels.find(channel).identifier + + if channel_identifier: + post_data["token"] = token + post_data["channels"] = channel_identifier + post_data["file"] = args + async_slack_api_upload_request(token, "files.upload", post_data) + @slack_buffer_required def command_talk(current_buffer, args): """ @@ -1719,6 +1740,14 @@ def async_slack_api_request(domain, token, request, post_data, priority=False): dbg("URL: {} context: {} params: {}".format(url, context, params)) w.hook_process_hashtable(url, params, 20000, "url_processor_cb", context) +def async_slack_api_upload_request(token, request, post_data, priority=False): + if not STOP_TALKING_TO_SLACK: + url = 'https://slack.com/api/{}'.format(request) + file_path = os.path.expanduser(post_data["file"]) + command = 'curl -F file=@{} -F channels={} -F token={} {}'.format(file_path, post_data["channels"], token, url) + context = pickle.dumps({"request": request, "token": token, "post_data": post_data}) + w.hook_process(command, 20000, "url_processor_cb", context) + # funny, right? big_data = {} -- cgit From c6ee4e8f89657571f20e1be5f3ff5b30454b5fcd Mon Sep 17 00:00:00 2001 From: Ryan Huber Date: Tue, 17 Nov 2015 17:59:03 +0000 Subject: clean up server aliasing --- wee_slack.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/wee_slack.py b/wee_slack.py index 55e9462..dd0fb6f 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -121,7 +121,7 @@ class SlackServer(object): self.nick = None self.name = None self.domain = None - self.server_alias = None + self.server_buffer_name = None self.login_data = None self.buffer = None self.token = token @@ -204,10 +204,11 @@ class SlackServer(object): dbg("connected to {}".format(self.domain)) self.identifier = self.domain - if not w.config_get_plugin("server_alias.{}".format(login_data["team"]["domain"])): - self.server_alias = login_data["team"]["domain"] + alias = w.config_get_plugin("server_alias.{}".format(login_data["team"]["domain"])) + if alias: + self.server_buffer_name = alias else: - self.server_alias = w.config_get_plugin("server_alias.{}".format(login_data["team"]["domain"])) + self.server_buffer_name = self.domain self.nick = login_data["self"]["name"] self.create_local_buffer() @@ -249,8 +250,8 @@ class SlackServer(object): self.buffer_prnt('{:<20} {}'.format("Team id", login_data["team"]["id"]), backlog=True) def create_local_buffer(self): - if not w.buffer_search("", self.domain): - self.buffer = w.buffer_new("{}.server".format(self.server_alias), "buffer_input_cb", "", "", "") + if not w.buffer_search("", self.server_buffer_name): + self.buffer = w.buffer_new(self.server_buffer_name, "buffer_input_cb", "", "", "") w.buffer_set(self.buffer, "nicklist", "1") w.nicklist_add_group(self.buffer, '', NICK_GROUP_HERE, "weechat.color.nicklist_group", 1) @@ -383,11 +384,11 @@ class Channel(object): self.members_table[user] = self.server.users.find(user) def create_buffer(self): - channel_buffer = w.buffer_search("", "{}.{}".format(self.server.server_alias, self.name)) + channel_buffer = w.buffer_search("", "{}.{}".format(self.server.server_buffer_name, self.name)) if channel_buffer: self.channel_buffer = channel_buffer else: - self.channel_buffer = w.buffer_new("{}.{}".format(self.server.server_alias, self.name), "buffer_input_cb", self.name, "", "") + self.channel_buffer = w.buffer_new("{}.{}".format(self.server.server_buffer_name, self.name), "buffer_input_cb", self.name, "", "") if self.type == "im": w.buffer_set(self.channel_buffer, "localvar_set_type", 'private') else: @@ -396,7 +397,7 @@ class Channel(object): buffer_list_update_next() def attach_buffer(self): - channel_buffer = w.buffer_search("", "{}.{}".format(self.server.server_alias, self.name)) + channel_buffer = w.buffer_search("", "{}.{}".format(self.server.server_buffer_name, self.name)) if channel_buffer != main_weechat_buffer: self.channel_buffer = channel_buffer w.buffer_set(self.channel_buffer, "localvar_set_nick", self.server.nick) @@ -431,7 +432,7 @@ class Channel(object): dbg("DEBUG: {} {} {}".format(self.identifier, self.name, e)) def fullname(self): - return "{}.{}".format(self.server.server_alias, self.name) + return "{}.{}".format(self.server.server_buffer_name, self.name) def has_user(self, name): return name in self.members @@ -1142,7 +1143,7 @@ def command_openweb(current_buffer, args): if trigger != "0": if args is None: channel = channels.find(current_buffer) - url = "{}/messages/{}".format(channel.server.domain, channel.name) + url = "{}/messages/{}".format(channel.server.server_buffer_name, channel.name) topic = w.buffer_get_string(channel.channel_buffer, "title") w.buffer_set(channel.channel_buffer, "title", "{}:{}".format(trigger, url)) w.hook_timer(1000, 0, 1, "command_openweb", json.dumps({"topic": topic, "buffer": current_buffer})) -- cgit