]> git.cworth.org Git - turbot/commitdiff
Add list of active hunts to the turbot Home tab
authorCarl Worth <cworth@cworth.org>
Wed, 14 Oct 2020 00:43:02 +0000 (17:43 -0700)
committerCarl Worth <cworth@cworth.org>
Wed, 14 Oct 2020 00:57:04 +0000 (17:57 -0700)
Finally starting to hook this Lambda up to our database for the first time.

turbot/commands.py
turbot/events.py
turbot/views.py
turbot_lambda/turbot_lambda.py

index 0ba1bcc5397a85d9cfe508b2f59670e99f870758..1b7098ca4937da7f1959aaf647628dc2401c9f9e 100644 (file)
@@ -1,7 +1,7 @@
 import requests
 import turbot.rot
 
-def rot(slack_client, body, args):
+def rot(turb, body, args):
     """Implementation of the /rot command
 
     The args string should be as follows:
index dcb2d0d1532de359affe053e385d98faf10db354..e8ea0b8a3da64e3fb422acc9c00ba9767f73714e 100644 (file)
@@ -1,9 +1,10 @@
 import turbot.views
 
-def app_home_opened(slack_client, body):
+def app_home_opened(turb, body):
     user_id = body['event']['user']
-    view = turbot.views.home(user_id, body)
-    slack_client.views_publish(user_id=user_id, view=view)
+    print("In app_home_opened function")
+    view = turbot.views.home(turb, user_id, body)
+    turb.slack_client.views_publish(user_id=user_id, view=view)
     return "OK"
 
 events = {
index ae897cce8f0740fd88d4f4c215061ab8796edf1e..aa0f010a1b651477f7442efc4a4ef9433124c5c1 100644 (file)
@@ -29,18 +29,21 @@ def button(label, name):
         "value": name
     }
 
-def home(user_id, body):
+def home(turb, user_id, body):
     """Returns a view to be published as the turbot home tab for user_id
 
     The body argument is a dictionary as provided by the Slack request.
     The return value is a dictionary suitable to be published to the
     Slack views_publish API."""
 
+    response = turb.db.Table("hunts").scan()
+    hunts = response['Items']
+
     return {
         "type": "home",
         "blocks": [
-            section(text("This is (or soon will be) a list of "
-                         + "available puzzle hunts)")),
+            section(text("*Active hunts*")),
+            *[section(text(hunt['name'])) for hunt in hunts if hunt['active']],
             actions(button("New hunt", "new_hunt"))
         ]
     }
index b6f4a36049360a4e154ac6bf1e6ca3217df8af69..b34c6f7cd209100264b9429161b6461279007e28 100644 (file)
@@ -4,6 +4,7 @@ import boto3
 import requests
 import json
 import os
+from types import SimpleNamespace
 
 import turbot.actions
 import turbot.commands
@@ -23,6 +24,12 @@ response = ssm.get_parameter(Name='SLACK_BOT_TOKEN', WithDecryption=True)
 slack_bot_token = response['Parameter']['Value']
 slack_client = WebClient(slack_bot_token)
 
+db = boto3.resource('dynamodb')
+
+turb = SimpleNamespace()
+turb.slack_client = slack_client
+turb.db = db
+
 def error(message):
     """Generate an error response for a Slack request
 
@@ -99,7 +106,7 @@ def event_callback_handler(body):
     type = body['event']['type']
 
     if type in turbot.events.events:
-        return turbot.events.events[type](slack_client, body)
+        return turbot.events.events[type](turb, body)
     return error("Unknown event type: {}".format(type))
 
 def turbot_interactive_or_slash_command(event, context):
@@ -167,6 +174,6 @@ def turbot_slash_command(body):
     args = body['text'][0]
 
     if command in turbot.commands.commands:
-        return turbot.commands.commands[command](slack_client, body, args)
+        return turbot.commands.commands[command](turb, body, args)
 
     return error("Command {} not implemented".format(command))