]> git.cworth.org Git - turbot/blobdiff - turbot_lambda/turbot_lambda.py
Give turbot/events.py the same dispatch-table treatment
[turbot] / turbot_lambda / turbot_lambda.py
index be8e099b5b2c25de64d052e77d8f9a6fa80ff739..b6f4a36049360a4e154ac6bf1e6ca3217df8af69 100644 (file)
@@ -98,8 +98,8 @@ def url_verification_handler(body):
 def event_callback_handler(body):
     type = body['event']['type']
 
-    if type == 'app_home_opened':
-        return turbot.events.app_home_opened(slack_client, body)
+    if type in turbot.events.events:
+        return turbot.events.events[type](slack_client, body)
     return error("Unknown event type: {}".format(type))
 
 def turbot_interactive_or_slash_command(event, context):
@@ -149,8 +149,11 @@ def turbot_block_action(payload):
     atype = action['type']
     avalue = action['value']
 
-    if atype == 'button' and avalue == 'new_hunt':
-        return turbot.actions.new_hunt(payload)
+    if (
+            atype in turbot.actions.actions
+            and avalue in turbot.actions.actions[atype]
+    ):
+        return turbot.actions.actions[atype][avalue](payload)
     return error("Unknown action of type/value: {}/{}".format(atype, avalue))
 
 def turbot_slash_command(body):
@@ -163,7 +166,7 @@ def turbot_slash_command(body):
     command = body['command'][0]
     args = body['text'][0]
 
-    if (command == "/rotlambda" or command == "/rot"):
-        return turbot.commands.rot(slack_client, body, args)
+    if command in turbot.commands.commands:
+        return turbot.commands.commands[command](slack_client, body, args)
 
     return error("Command {} not implemented".format(command))