From: Carl Worth Date: Tue, 13 Oct 2020 23:42:00 +0000 (-0700) Subject: Add a dispatch table for actions as well X-Git-Url: https://git.cworth.org/git?p=turbot;a=commitdiff_plain;h=9d0b128dcb0af08c9586d526e8ed1c01a57e6973 Add a dispatch table for actions as well Just as for slash commands in the previous commit, this will help make turbot/actions.py easier to maintain. --- diff --git a/turbot/actions.py b/turbot/actions.py index 8103c5d..daf0227 100644 --- a/turbot/actions.py +++ b/turbot/actions.py @@ -6,3 +6,9 @@ def new_hunt(payload): 'statusCode': 200, 'body': 'OK' } + +actions = { + "button": { + "new_hunt": new_hunt + } +} diff --git a/turbot_lambda/turbot_lambda.py b/turbot_lambda/turbot_lambda.py index e22c4eb..5420b33 100644 --- a/turbot_lambda/turbot_lambda.py +++ b/turbot_lambda/turbot_lambda.py @@ -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):