From 9d0b128dcb0af08c9586d526e8ed1c01a57e6973 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Tue, 13 Oct 2020 16:42:00 -0700 Subject: [PATCH] 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. --- turbot/actions.py | 6 ++++++ turbot_lambda/turbot_lambda.py | 7 +++++-- 2 files changed, 11 insertions(+), 2 deletions(-) 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): -- 2.45.2