diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2017-09-16 23:36:14 +0200 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2017-09-17 01:40:29 +0200 |
commit | b6be0949f63a8221ad32ac972b1a0288ed56c12d (patch) | |
tree | f1ab8c7da029cc5c194a50c623cc736270fe599f /wee_slack.py | |
parent | 9250acdc48ae4924d9b488ccbf5cf61fdadae67a (diff) | |
download | wee-slack-b6be0949f63a8221ad32ac972b1a0288ed56c12d.tar.gz |
Add completion of custom emojis
This loads the list of custom emojis for each team after wee-slack has
connected to the team, and adds them to the emoji completion list for
that team.
The list of custom emojis is only loaded if the list of the standard
emojis has been loaded, since it would be a bit strange to only have
completions of the custom emojis.
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 dd0469c..620e16b 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -787,9 +787,9 @@ def emoji_completion_cb(data, completion_item, current_buffer, completion): current_buffer = w.current_buffer() current_channel = EVENTROUTER.weechat_controller.buffers.get(current_buffer, None) - if current_channel is None or not EMOJI: + if current_channel is None: return w.WEECHAT_RC_OK - for e in EMOJI['emoji']: + for e in current_channel.team.emoji_completions: w.hook_completion_list_add(completion, ":" + e + ":", 0, w.WEECHAT_LIST_POS_SORT) return w.WEECHAT_RC_OK @@ -944,6 +944,7 @@ class SlackTeam(object): 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', "")) + self.load_emoji_completions() def __eq__(self, compare_str): if compare_str == self.token or compare_str == self.domain or compare_str == self.subdomain: @@ -951,6 +952,14 @@ class SlackTeam(object): else: return False + def load_emoji_completions(self): + if EMOJI: + self.emoji_completions = list(EMOJI["emoji"]) + s = SlackRequest(self.token, "emoji.list", {}, team_hash=self.team_hash) + self.eventrouter.receive(s) + else: + self.emoji_completions = [] + def add_channel(self, channel): self.channels[channel["id"]] = channel channel.set_related_server(self) @@ -2105,6 +2114,14 @@ def handle_rtmstart(login_data, eventrouter): # self.identifier = self.domain + +def handle_emojilist(emoji_json, eventrouter, **kwargs): + if emoji_json["ok"]: + request_metadata = pickle.loads(emoji_json["wee_slack_request_metadata"]) + team = eventrouter.teams[request_metadata.team_hash] + team.emoji_completions.extend(emoji_json["emoji"].keys()) + + def handle_channelsinfo(channel_json, eventrouter, **kwargs): request_metadata = pickle.loads(channel_json["wee_slack_request_metadata"]) team = eventrouter.teams[request_metadata.team_hash] |