diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2018-08-19 21:33:45 +0200 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2018-08-20 00:43:08 +0200 |
commit | 1a4086647d9fe0c9c4871b5be3f3cbdd6934c784 (patch) | |
tree | 45e6a2cea543d57f7c8f145400ffc8a2d446fc72 /wee_slack.py | |
parent | c0419e6a95552fcb8e0e4c5f42360f6cd0de706e (diff) | |
download | wee-slack-1a4086647d9fe0c9c4871b5be3f3cbdd6934c784.tar.gz |
Add a helper for getting functions with a prefix
Diffstat (limited to 'wee_slack.py')
-rw-r--r-- | wee_slack.py | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/wee_slack.py b/wee_slack.py index 14b7964..dc064dd 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -245,6 +245,11 @@ def get_nick_color_name(nick): return w.info_get(info_name_prefix + "nick_color_name", nick) +def get_functions_with_prefix(prefix): + return {name[len(prefix):]: ref for name, ref in globals().items() + if name.startswith(prefix)} + + ##### BEGIN NEW IGNORED_EVENTS = [ @@ -275,10 +280,10 @@ class EventRouter(object): self.weechat_controller = WeechatController(self) self.previous_buffer = "" self.reply_buffer = {} - self.cmds = {k[8:]: v for k, v in globals().items() if k.startswith("command_")} - self.proc = {k[8:]: v for k, v in globals().items() if k.startswith("process_")} - self.handlers = {k[7:]: v for k, v in globals().items() if k.startswith("handle_")} - self.local_proc = {k[14:]: v for k, v in globals().items() if k.startswith("local_process_")} + self.cmds = get_functions_with_prefix("command_") + self.proc = get_functions_with_prefix("process_") + self.handlers = get_functions_with_prefix("handle_") + self.local_proc = get_functions_with_prefix("local_process_") self.shutting_down = False self.recording = False self.recording_path = "/tmp" @@ -3692,7 +3697,7 @@ def load_emoji(): def setup_hooks(): - cmds = {k[8:]: v for k, v in globals().items() if k.startswith("command_")} + cmds = get_functions_with_prefix("command_") w.bar_item_new('slack_typing_notice', '(extra)typing_bar_item_cb', '') |