]> git.cworth.org Git - turbot/commitdiff
Add a list of puzzles under each hunt on the Turbot home tab
authorCarl Worth <cworth@cworth.org>
Thu, 22 Oct 2020 11:08:30 +0000 (04:08 -0700)
committerCarl Worth <cworth@cworth.org>
Thu, 22 Oct 2020 12:06:39 +0000 (05:06 -0700)
Giving a simple overview of all puzzles in one place, including an emoji
indication of whether the puzzle is solved or not.

turbot/blocks.py
turbot/events.py

index a18c0558a072cb18e7284123b4311d55a2537916..27e69f4d6d9d61140a16e4fa71cd30fcfe9d75e3 100644 (file)
@@ -1,3 +1,8 @@
+def divider_block():
+    return {
+        "type": "divider"
+    }
+
 def text_block(body):
     return {
         "text": {
index eff57786d252902847f79d548e3495ca6901eee2..c0549828b069d7cf0e8f5e9c0dc527325617ad39 100644 (file)
@@ -1,8 +1,9 @@
 from turbot.blocks import (
-    section_block, text_block, button_block, actions_block
+    section_block, text_block, button_block, actions_block, divider_block
 )
 import turbot.sheets
 import turbot.slack
+import itertools
 
 TURBOT_USER_ID = 'U01B9QM4P9R'
 
@@ -11,13 +12,36 @@ events = {}
 lambda_success = {'statusCode': 200}
 lambda_error = {'statusCode': 400}
 
-def hunt_block(hunt):
+def puzzle_block(puzzle):
+    name = puzzle['name']
+    status = puzzle['status']
+    channel_id = puzzle['channel_id']
+    status_emoji = ''
+
+    if status == 'solved':
+        status_emoji = ":ballot_box_with_check:"
+    else:
+        status_emoji = ":white_square:"
+
+    puzzle_text = "{} {}: <#{}>".format(status_emoji, name, channel_id)
+
+    return section_block(text_block(puzzle_text))
+
+def hunt_block(turb, hunt):
     name = hunt['name']
+    hunt_id = hunt['hunt_id']
     channel_id = hunt['channel_id']
 
-    text = "{}: <#{}>".format(name, channel_id)
+    response = turb.db.Table(hunt_id).scan()
+    puzzles = response['Items']
+
+    hunt_text = "*{}*: <#{}>".format(name, channel_id)
 
-    return section_block(text_block(text))
+    return [
+        section_block(text_block(hunt_text)),
+        *[puzzle_block(puzzle) for puzzle in puzzles],
+        divider_block()
+    ]
 
 def home(turb, user_id):
     """Returns a view to be published as the turbot home tab for user_id
@@ -32,11 +56,17 @@ def home(turb, user_id):
     except Exception:
         hunts = []
 
+    hunt_blocks = []
+    for hunt in hunts:
+        if hunt['active']:
+            hunt_blocks += hunt_block(turb, hunt)
+
     return {
         "type": "home",
         "blocks": [
             section_block(text_block("*Active hunts*")),
-            *[hunt_block(hunt) for hunt in hunts if hunt['active']],
+            divider_block(),
+            * hunt_blocks,
             actions_block(button_block("New hunt", "new_hunt"))
         ]
     }