]> git.cworth.org Git - turbot/commitdiff
Add a dispatch table to turbot.commands
authorCarl Worth <cworth@cworth.org>
Tue, 13 Oct 2020 23:35:37 +0000 (16:35 -0700)
committerCarl Worth <cworth@cworth.org>
Tue, 13 Oct 2020 23:38:36 +0000 (16:38 -0700)
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.

turbot/commands.py
turbot_lambda/turbot_lambda.py

index 2a1f3e5b3ea618574b94cb53db8cace08b46f3e9..0ba1bcc5397a85d9cfe508b2f59670e99f870758 100644 (file)
@@ -35,3 +35,7 @@ def rot(slack_client, body, args):
         'statusCode': 200,
         'body': ""
     }
+
+commands = {
+    "/rot": rot
+}
index be8e099b5b2c25de64d052e77d8f9a6fa80ff739..e22c4ebb0177625f844081262c5288423a53a2a2 100644 (file)
@@ -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))