diff options
author | Ryan Huber <rhuber@gmail.com> | 2017-02-06 11:44:06 -0800 |
---|---|---|
committer | Ryan Huber <rhuber@gmail.com> | 2017-02-06 11:44:06 -0800 |
commit | 8c4b8baeba8db45e98550fb2f92fe13322f4562c (patch) | |
tree | 7f2df960f3c301ea9796f09736821adcc3ad9a5a /wee_slack.py | |
parent | 6bdc0d9cdddc6a84716550395699da61e04bd9ff (diff) | |
download | wee-slack-8c4b8baeba8db45e98550fb2f92fe13322f4562c.tar.gz |
highlights server side
Diffstat (limited to 'wee_slack.py')
-rw-r--r-- | wee_slack.py | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/wee_slack.py b/wee_slack.py index 2572de5..beaeec5 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -753,9 +753,7 @@ class SlackTeam(object): try: if self.channels: for c in channels.keys(): - #print 'got {} '.format(c) if not self.channels.get(c): - #print 'new {}'.format(c) self.channels[c] = channels[c] except: self.channels = channels @@ -774,6 +772,8 @@ class SlackTeam(object): # self.channel_set_related_server(c) # Last step is to make sure my nickname is the set color self.users[self.myidentifier].force_color(w.config_string(w.config_get('weechat.color.chat_nick_self'))) + # This highlight step must happen after we have set related server + self.set_highlight_words(kwargs.get('highlight_words', "")) def __eq__(self, compare_str): if compare_str == self.token or compare_str == self.domain or compare_str == self.subdomain: return True @@ -799,6 +799,11 @@ class SlackTeam(object): w.buffer_set(self.channel_buffer, "nicklist", "1") def set_muted_channels(self, muted_str): self.muted_channels = {x for x in muted_str.split(',')} + def set_highlight_words(self, highlight_str): + self.highlight_words = {x for x in highlight_str.split(',')} + if len(self.highlight_words) > 0: + for v in self.channels.itervalues(): + v.set_highlights() def formatted_name(self, **kwargs): return self.domain def buffer_prnt(self, data): @@ -966,6 +971,12 @@ class SlackChannel(object): pass def set_related_server(self, team): self.team = team + def set_highlights(self): + #highlight my own name and any set highlights + if self.channel_buffer: + highlights = self.team.highlight_words.union({'@' + self.team.nick}) + h_str = ",".join(highlights) + w.buffer_set(self.channel_buffer, "highlight_words", h_str) def create_buffer(self): """ incomplete (muted doesn't work) @@ -1018,6 +1029,9 @@ class SlackChannel(object): def buffer_prnt(self, nick, text, timestamp, **kwargs): data = "{}\t{}".format(nick, text) ts = SlackTS(timestamp) + #without this, DMs won't open automatically + if not self.channel_buffer: + self.open(update_remote=False) if self.channel_buffer: #backlog messages - we will update the read marker as we print these try: @@ -1666,6 +1680,7 @@ def handle_rtmstart(login_data, eventrouter): bots, channels, muted_channels=login_data["self"]["prefs"]["muted_channels"], + highlight_words=login_data["self"]["prefs"]["highlight_words"], ) eventrouter.register_team(t) @@ -1731,6 +1746,8 @@ def process_pref_change(message_json, eventrouter, **kwargs): team = kwargs["team"] if message_json['name'] == u'muted_channels': team.set_muted_channels(message_json['value']) + elif message_json['name'] == u'highlight_words': + team.set_highlight_words(message_json['value']) else: dbg("Preference change not implemented: {}\n".format(message_json['name'])) |