]> git.cworth.org Git - turbot/commitdiff
Wire up a function to handle the edit_puzzle button
authorCarl Worth <cworth@cworth.org>
Thu, 7 Jan 2021 17:05:34 +0000 (09:05 -0800)
committerCarl Worth <cworth@cworth.org>
Thu, 7 Jan 2021 20:07:14 +0000 (12:07 -0800)
It doesn't actually _do_ anything yet, but should at least prevent the
warning sign which was appearing before.

And this should let us see if the action_id field is a good way of
plumbing the hunt_id and puzzle_id through to the handler for the
press of the edit_puzzle button.

turbot/blocks.py
turbot/interaction.py
turbot/puzzle.py

index cfef7f6a76ecf481224043d5a52b41565f46280b..c037b03217f0ed117b823dc2141dfe03d05a6297 100644 (file)
@@ -23,8 +23,9 @@ def actions_block(*elements):
         "elements": list(elements)
     }
 
-def button_block(label, name):
-    return {
+def button_block(label, name, extra=None):
+
+    block = {
         "type": "button",
         "text": {
             "type": "plain_text",
@@ -34,6 +35,11 @@ def button_block(label, name):
         "value": name
     }
 
+    if extra:
+        block['action_id'] = extra
+
+    return block
+
 def accessory_block(main, accessory):
     return {
         **main,
index b81541c645db5fc549458fadb7ff8678c8fad09e..f9fcedee34b174dcc4bc2bd0669e3214c9ea72c9 100644 (file)
@@ -16,10 +16,16 @@ from turbot.slack import slack_send_message
 import shlex
 
 actions = {}
+actions['button'] = {}
 commands = {}
 submission_handlers = {}
 
 # Hunt/Puzzle IDs are restricted to lowercase letters, numbers, and underscores
+#
+# Note: This restriction not only allows for hunt and puzzle ID values to
+# be used as Slack channel names, but it also allows for '-' as a valid
+# separator between a hunt and a puzzle ID (for example in the puzzle
+# edit dialog where a single attribute must capture both values).
 valid_id_re = r'^[_a-z0-9]+$'
 
 lambda_ok = {'statusCode': 200}
@@ -63,6 +69,15 @@ def multi_static_select(turb, payload):
 
 actions['multi_static_select'] = {"*": multi_static_select}
 
+def edit_puzzle(turb, payload):
+    """Handler for the action of user pressing an edit_puzzle button"""
+
+    print("DEBUG: In edit_puzzle with payload: {}".format(str(payload)))
+
+    return lambda_ok
+
+actions['button']['edit_puzzle'] = edit_puzzle
+
 def new_hunt(turb, payload):
     """Handler for the action of user pressing the new_hunt button"""
 
@@ -88,7 +103,7 @@ def new_hunt(turb, payload):
 
     return lambda_ok
 
-actions['button'] = {"new_hunt": new_hunt}
+actions['button']['new_hunt'] = new_hunt
 
 def new_hunt_submission(turb, payload, metadata):
     """Handler for the user submitting the new hunt modal
index 3c85df487f7298a42370f13bc5e91d1553dbb1e5..81e0630f88c08416097ec55aa972ccde18387164 100644 (file)
@@ -69,10 +69,15 @@ def puzzle_blocks(puzzle):
         ', '.join(links), state_str
     )
 
+    # Combining hunt ID and puzzle ID together here is safe because
+    # both IDs are restricted to not contain a hyphen, (see
+    # valid_id_re in interaction.py)
+    hunt_and_puzzle = "{}-{}".format(puzzle['hunt_id'], puzzle['puzzle_id'])
+
     return [
         accessory_block(
             section_block(text_block(puzzle_text)),
-            button_block("✏", puzzle['puzzle_id'])
+            button_block("✏", "edit_puzzle", hunt_and_puzzle)
         )
     ]