]> git.cworth.org Git - turbot/commitdiff
Add an edit button next to each puzzle
authorCarl Worth <cworth@cworth.org>
Thu, 7 Jan 2021 04:42:21 +0000 (20:42 -0800)
committerCarl Worth <cworth@cworth.org>
Thu, 7 Jan 2021 04:44:29 +0000 (20:44 -0800)
This will appear in both the Turbot home screen as well as in the
output from the /hunt command.

turbot/blocks.py
turbot/hunt.py
turbot/puzzle.py
turbot/round.py

index 661cff37287d0fbee5a9fddb37220f7c8ef17630..cfef7f6a76ecf481224043d5a52b41565f46280b 100644 (file)
@@ -34,6 +34,14 @@ def button_block(label, name):
         "value": name
     }
 
+def accessory_block(main, accessory):
+    return {
+        **main,
+        "accessory": {
+            **accessory
+        }
+    }
+
 def input_block(label, name, placeholder, optional=False):
     return {
         "type": "input",
index d6ca6b6909344bb1978ade4ac2079424379fbc8b..ccab28daa4e004de56229291de50dc7b2b50e926 100644 (file)
@@ -1,6 +1,6 @@
 from turbot.blocks import section_block, text_block, divider_block
 from turbot.round import round_blocks
-from turbot.puzzle import puzzle_block, puzzle_matches_all
+from turbot.puzzle import puzzle_blocks, puzzle_matches_all
 from turbot.channel import channel_url
 from boto3.dynamodb.conditions import Key
 
@@ -108,7 +108,7 @@ def hunt_blocks(turb, hunt, puzzle_status='unsolved', search_terms=[]):
         stray_text = "*Puzzles with no assigned round*"
         blocks.append(section_block(text_block(stray_text)))
         for puzzle in stray_puzzles:
-            blocks.append(puzzle_block(puzzle))
+            blocks += puzzle_blocks(puzzle)
 
     blocks.append(divider_block())
 
index 7db006b9b237702289a41125e81a4e169e0674d3..3c85df487f7298a42370f13bc5e91d1553dbb1e5 100644 (file)
@@ -1,4 +1,6 @@
-from turbot.blocks import section_block, text_block
+from turbot.blocks import (
+    section_block, text_block, button_block, accessory_block
+)
 from turbot.channel import channel_url
 from boto3.dynamodb.conditions import Key
 import re
@@ -24,7 +26,7 @@ def find_puzzle_for_url(turb, hunt_id, url):
 
     return response['Items'][0]
 
-def puzzle_block(puzzle):
+def puzzle_blocks(puzzle):
     """Generate Slack blocks for a puzzle
 
     The puzzle argument should be a dictionary as returned from the
@@ -67,7 +69,12 @@ def puzzle_block(puzzle):
         ', '.join(links), state_str
     )
 
-    return section_block(text_block(puzzle_text))
+    return [
+        accessory_block(
+            section_block(text_block(puzzle_text)),
+            button_block("✏", puzzle['puzzle_id'])
+        )
+    ]
 
 def puzzle_matches_one(puzzle, pattern):
     """Returns True if this puzzle matches the given string (regexp)
index 3c4042be6a6d0e94094ba3282c8cc0198ae403b3..3a4266faae1483e4d2e68351de9a825f3eb1309f 100644 (file)
@@ -1,4 +1,4 @@
-from turbot.puzzle import puzzle_block
+from turbot.puzzle import puzzle_blocks
 from turbot.blocks import section_block, text_block
 
 def round_blocks(round, puzzles):
@@ -26,6 +26,6 @@ def round_blocks(round, puzzles):
             continue
         if round not in puzzle['rounds']:
             continue
-        blocks.append(puzzle_block(puzzle))
+        blocks += puzzle_blocks(puzzle)
 
     return blocks