diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2018-01-16 23:54:56 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-16 23:54:56 +0100 |
commit | 0f32714d0abd47ec659d6e25ec5c4da6494d774b (patch) | |
tree | c1f8c2afc411092faeff19169d6324ead99caeb0 /wee_slack.py | |
parent | 5e16fa41535a0347b34adca89a13560aec6d36bc (diff) | |
parent | cfe2911d300625a3a22dd8afecb32b70eeea02d9 (diff) | |
download | wee-slack-0f32714d0abd47ec659d6e25ec5c4da6494d774b.tar.gz |
Merge pull request #437 from trygveaa/completion-of-custom-emojis
Add completion of custom emojis
Diffstat (limited to 'wee_slack.py')
-rw-r--r-- | wee_slack.py | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/wee_slack.py b/wee_slack.py index 49ec61e..16d5569 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -124,6 +124,8 @@ if hasattr(ssl, "get_default_verify_paths") and callable(ssl.get_default_verify_ if ssl_defaults.cafile is not None: sslopt_ca_certs = {'ca_certs': ssl_defaults.cafile} +EMOJI = [] + ###### Unicode handling @@ -837,7 +839,7 @@ def emoji_completion_cb(data, completion_item, current_buffer, completion): 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 @@ -991,6 +993,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: @@ -998,6 +1001,12 @@ class SlackTeam(object): else: return False + def load_emoji_completions(self): + self.emoji_completions = list(EMOJI) + if self.emoji_completions: + s = SlackRequest(self.token, "emoji.list", {}, team_hash=self.team_hash) + self.eventrouter.receive(s) + def add_channel(self, channel): self.channels[channel["id"]] = channel channel.set_related_server(self) @@ -2148,6 +2157,14 @@ def handle_rtmstart(login_data, eventrouter): dbg("connected to {}".format(t.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] @@ -2534,6 +2551,11 @@ def process_reaction_removed(message_json, eventrouter, **kwargs): else: dbg("Reaction to item type not supported: " + str(message_json)) + +def process_emoji_changed(message_json, eventrouter, **kwargs): + team = kwargs['team'] + team.load_emoji_completions() + ###### New module/global methods def render_formatting(text): @@ -3361,16 +3383,12 @@ def create_slack_debug_buffer(): def load_emoji(): try: - global EMOJI DIR = w.info_get("weechat_dir", "") - # no idea why this does't work w/o checking the type?! - dbg(type(DIR), 0) - ef = open('{}/weemoji.json'.format(DIR), 'r') - EMOJI = json.loads(ef.read()) - ef.close() - except: - dbg("Unexpected error: {}".format(sys.exc_info()), 5) - return w.WEECHAT_RC_OK + with open('{}/weemoji.json'.format(DIR), 'r') as ef: + return json.loads(ef.read())["emoji"] + except Exception as e: + dbg("Couldn't load emoji list: {}".format(e), 5) + return [] def setup_hooks(): @@ -3720,7 +3738,7 @@ if __name__ == "__main__": w.hook_config("plugins.var.python." + SCRIPT_NAME + ".*", "config_changed_cb", "") w.hook_modifier("input_text_for_buffer", "input_text_for_buffer_cb", "") - load_emoji() + EMOJI.extend(load_emoji()) setup_hooks() # attach to the weechat hooks we need |