From: Carl Worth Date: Tue, 13 Oct 2020 23:35:37 +0000 (-0700) Subject: Add a dispatch table to turbot.commands X-Git-Url: https://git.cworth.org/git?p=turbot;a=commitdiff_plain;h=7bb350e410b3a2c98c3fb7daadb8fb83583cbdea Add a dispatch table to turbot.commands This allows the turbot/commands.py file to be self-sufficient, in the sense that adding a new command will not require changing any of the dispatch code above in turbot_lambda.py, but instead just the local dispatch table. --- diff --git a/turbot/commands.py b/turbot/commands.py index 2a1f3e5..0ba1bcc 100644 --- a/turbot/commands.py +++ b/turbot/commands.py @@ -35,3 +35,7 @@ def rot(slack_client, body, args): 'statusCode': 200, 'body': "" } + +commands = { + "/rot": rot +} diff --git a/turbot_lambda/turbot_lambda.py b/turbot_lambda/turbot_lambda.py index be8e099..e22c4eb 100644 --- a/turbot_lambda/turbot_lambda.py +++ b/turbot_lambda/turbot_lambda.py @@ -163,7 +163,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))