diff options
author | Ryan Huber <rhuber@gmail.com> | 2014-04-03 22:59:24 -0700 |
---|---|---|
committer | Ryan Huber <rhuber@gmail.com> | 2014-04-03 22:59:24 -0700 |
commit | 12951031b4b3f2c54d989aa3d8d7560d7c34ebf5 (patch) | |
tree | c396e22112506fbff61a0af562ee117d663cda36 /wee_slack.py | |
parent | 6f3c4d2d15fc5d4d9410aa5cf40ed24deb0178e2 (diff) | |
download | wee-slack-12951031b4b3f2c54d989aa3d8d7560d7c34ebf5.tar.gz |
remove evals cause eval is a bad idea :)
Diffstat (limited to 'wee_slack.py')
-rw-r--r-- | wee_slack.py | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/wee_slack.py b/wee_slack.py index 7afe7e8..6a0792b 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -28,11 +28,10 @@ def slack_command_cb(data, current_buffer, args): function_name, args = a[0], a[1] else: function_name, args = a[0], None - function_name = "command_"+function_name -# try: - eval(function_name)(args) -# except: -# w.prnt("", "Command not found "+function_name) + try: + cmds[function_name](args) + except: + w.prnt("", "Command not found "+function_name) return w.WEECHAT_RC_OK def command_test(args): @@ -96,9 +95,9 @@ def slack_cb(data, fd): pass dereference_hash(message_json) #dispatch here - function_name = "process_"+message_json["type"] + function_name = message_json["type"] try: - eval(function_name)(message_json) + proc[function_name](message_json) except: #w.prnt("", "Function not implemented "+function_name) pass @@ -406,8 +405,9 @@ if __name__ == "__main__": w.hook_signal('buffer_switch', "buffer_switch_cb", "") w.hook_signal('window_switch', "buffer_switch_cb", "") w.hook_signal('input_text_changed', "typing_notification_cb", "") - commands = [x[8:] for x in dir() if x.startswith('command_')] - w.hook_command('slack','Plugin to allow typing notification and sync of read markers for slack.com', 'stuff', 'stuff2', '|'.join(commands), 'slack_command_cb', '') + cmds = {k[8:]: v for k, v in globals().items() if k.startswith("command_")} + proc = {k[8:]: v for k, v in globals().items() if k.startswith("process_")} + w.hook_command('slack','Plugin to allow typing notification and sync of read markers for slack.com', 'stuff', 'stuff2', '|'.join(cmds.keys()), 'slack_command_cb', '') w.bar_item_new('slack_typing_notice', 'typing_bar_item_cb', '') else: w.prnt("", 'You need to configure this plugin!') |