diff options
-rw-r--r-- | README.md | 10 | ||||
-rw-r--r-- | wee_slack.py | 42 |
2 files changed, 35 insertions, 17 deletions
@@ -45,7 +45,6 @@ Dependencies ------------ * WeeChat 1.1+ http://weechat.org/ * websocket-client https://pypi.python.org/pypi/websocket-client/ - * curl http://curl.haxx.se/ Setup ------ @@ -65,19 +64,14 @@ wee-slack doesn't use the Slack IRC gateway. If you currently connect via the ga ####1. Install dependencies -##### OSX +##### OSX and Linux ``` pip install websocket-client ``` -##### Linux (ubuntu) -``` -sudo apt-get install curl -pip install websocket-client -``` ##### FreeBSD ``` -pkg install curl py27-websocket-client py27-six +pkg install py27-websocket-client py27-six ``` ####2. copy wee_slack.py to ~/.weechat/python/autoload diff --git a/wee_slack.py b/wee_slack.py index e222966..000562b 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -287,6 +287,10 @@ class SlackServer(object): item["last_read"] = 0 name = self.users.find(item["user"]).name self.add_channel(DmChannel(self, name, item["id"], item["is_open"], item["last_read"])) + for item in data['self']['prefs']['muted_channels'].split(','): + if item == '': + continue + self.channels.find(item).muted = True for item in self.channels: item.get_history() @@ -338,6 +342,7 @@ class Channel(object): self.last_received = None self.messages = [] self.scrolling = False + self.muted = False if active: self.create_buffer() self.attach_buffer() @@ -569,6 +574,8 @@ class Channel(object): tags = "notify_highlight" elif user != self.server.nick and self.name in self.server.users: tags = "notify_private,notify_message" + elif self.muted: + tags = "no_highlight,notify_none,logger_backlog_end" elif user in [x.strip() for x in w.prefix("join"), w.prefix("quit")]: tags = "irc_smart_filter" else: @@ -1170,6 +1177,19 @@ def process_pong(message_json): pass +def process_pref_change(message_json): + server = servers.find(message_json["myserver"]) + if message_json['name'] == u'muted_channels': + muted = message_json['value'].split(',') + for c in server.channels: + if c.identifier in muted: + c.muted = True + else: + c.muted = False + else: + dbg("Preference change not implemented: {}\n{}".format(message_json['name'])) + + def process_team_join(message_json): server = servers.find(message_json["myserver"]) item = message_json["user"] @@ -1687,6 +1707,8 @@ def complete_next_cb(data, buffer, command): # If we're on a non-word, look left for something to complete while current_pos >= 0 and input[current_pos] != '@' and not input[current_pos].isalnum(): current_pos = current_pos - 1 + if current_pos < 0: + current_pos = 0 for l in range(current_pos, 0, -1): if input[l] != '@' and not input[l].isalnum(): word_start = l + 1 @@ -1708,14 +1730,15 @@ def complete_next_cb(data, buffer, command): # Slack specific requests -# NOTE: switched to async/curl because sync slowed down the UI +# NOTE: switched to async because sync slowed down the UI def async_slack_api_request(domain, token, request, post_data, priority=False): if not STOP_TALKING_TO_SLACK: post_data["token"] = token - url = 'https://{}/api/{}'.format(domain, request) - command = 'curl -A "wee_slack {}" -s --data "{}" {}'.format(SCRIPT_VERSION, urllib.urlencode(post_data), url) + url = 'url:https://{}/api/{}?{}'.format(domain, request, urllib.urlencode(post_data)) context = pickle.dumps({"request": request, "token": token, "post_data": post_data}) - w.hook_process(command, 20000, "url_processor_cb", context) + params = { 'useragent': 'wee_slack {}'.format(SCRIPT_VERSION) } + dbg("URL: {} context: {} params: {}".format(url, context, params)) + w.hook_process_hashtable(url, params, 20000, "url_processor_cb", context) # funny, right? big_data = {} @@ -1731,8 +1754,8 @@ def url_processor_cb(data, command, return_code, out, err): try: my_json = json.loads(big_data[identifier]) except: - dbg("curl failed, doing again...") - dbg("curl length: {} identifier {}\n{}".format(len(big_data[identifier]), identifier, data)) + dbg("request failed, doing again...") + dbg("response length: {} identifier {}\n{}".format(len(big_data[identifier]), identifier, data)) my_json = False big_data.pop(identifier, None) @@ -1755,9 +1778,10 @@ def url_processor_cb(data, command, return_code, out, err): if "channel" in my_json: if "members" in my_json["channel"]: channels.find(my_json["channel"]["id"]).members = set(my_json["channel"]["members"]) - elif return_code != -1: - big_data.pop(identifier, None) - dbg("return code: {}".format(return_code)) + else: + if return_code != -1: + big_data.pop(identifier, None) + dbg("return code: {}, data: {}".format(return_code, data)) return w.WEECHAT_RC_OK |