]> git.cworth.org Git - turbot/commitdiff
Add a dispatch table for actions as well
authorCarl Worth <cworth@cworth.org>
Tue, 13 Oct 2020 23:42:00 +0000 (16:42 -0700)
committerCarl Worth <cworth@cworth.org>
Tue, 13 Oct 2020 23:52:53 +0000 (16:52 -0700)
Just as for slash commands in the previous commit, this will help make
turbot/actions.py easier to maintain.

turbot/actions.py
turbot_lambda/turbot_lambda.py

index 8103c5d4c3ba0e55d394f5d4134f289ceb9aae01..daf0227bb870fb1635afc8eb2abe8bdfb0352d0d 100644 (file)
@@ -6,3 +6,9 @@ def new_hunt(payload):
         'statusCode': 200,
         'body': 'OK'
     }
+
+actions = {
+    "button": {
+        "new_hunt": new_hunt
+    }
+}
index e22c4ebb0177625f844081262c5288423a53a2a2..5420b33dc36726a7e63423f4bb08a678a5beea11 100644 (file)
@@ -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):