aboutsummaryrefslogtreecommitdiffstats
path: root/wee_slack.py
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2017-09-16 22:11:34 +0200
committerTrygve Aaberge <trygveaa@gmail.com>2017-09-17 00:04:04 +0200
commit4f6e039ad420cc2e8a7846ee97a939e59d37bde2 (patch)
treea93b5bb88b39d09a74bb623719d9539ce753af02 /wee_slack.py
parent564d48486a7087727ffcc5ec1b77430b96e66469 (diff)
downloadwee-slack-4f6e039ad420cc2e8a7846ee97a939e59d37bde2.tar.gz
Refactor emoji list loading
This prevents an error that EMOJI is not defined when trying to tab complete after the emoji list could not be loaded.
Diffstat (limited to 'wee_slack.py')
-rw-r--r--wee_slack.py12
1 files changed, 5 insertions, 7 deletions
diff --git a/wee_slack.py b/wee_slack.py
index 0caab43..dd0469c 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -787,7 +787,7 @@ 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:
+ if current_channel is None or not EMOJI:
return w.WEECHAT_RC_OK
for e in EMOJI['emoji']:
w.hook_completion_list_add(completion, ":" + e + ":", 0, w.WEECHAT_LIST_POS_SORT)
@@ -3229,14 +3229,11 @@ def create_slack_debug_buffer():
def load_emoji():
try:
- global EMOJI
DIR = w.info_get("weechat_dir", "")
- ef = open('{}/weemoji.json'.format(DIR), 'r')
- EMOJI = json.loads(ef.read())
- ef.close()
+ with open('{}/weemoji.json'.format(DIR), 'r') as ef:
+ return json.loads(ef.read())
except Exception as e:
dbg("Couldn't load emoji list: {}".format(e), 5)
- return w.WEECHAT_RC_OK
def setup_hooks():
@@ -3564,7 +3561,8 @@ if __name__ == "__main__":
w.hook_config("plugins.var.python." + SCRIPT_NAME + ".*", "config_changed_cb", "")
- load_emoji()
+ global EMOJI
+ EMOJI = load_emoji()
setup_hooks()
# attach to the weechat hooks we need