]> git.cworth.org Git - turbot/blobdiff - turbot/interaction.py
Report change in a puzzle's solved status to the main hunt channel
[turbot] / turbot / interaction.py
index 69db52149d1eda35e3a62fda6b70b1184e0476ba..bfb759ada53f9395ac0f8c629ec0fd0991a4b55f 100644 (file)
@@ -179,6 +179,7 @@ def edit_puzzle_submission(turb, payload, metadata):
     puzzle['sheet_url'] = meta['sheet_url']
 
     state = payload['view']['state']['values']
+    user_id = payload['user']['id']
 
     puzzle['name'] = state['name']['name']['value']
     url = state['url']['url']['value']
@@ -238,6 +239,27 @@ def edit_puzzle_submission(turb, payload, metadata):
     # Update the puzzle in the database
     turb.table.put_item(Item=puzzle)
 
+    # Inform the puzzle channel about the edit
+    edit_message = "Puzzle edited by <@{}>".format(user_id)
+    blocks = ([section_block(text_block(edit_message+":\n"))] +
+              puzzle_blocks(puzzle, include_rounds=True))
+    slack_send_message(
+        turb.slack_client, puzzle['channel_id'],
+        edit_message, blocks=blocks)
+
+    # Also inform the hunt if the puzzle's solved status changed
+    if puzzle['status'] != old_puzzle['status']:
+        hunt = find_hunt_for_hunt_id(turb, puzzle['hunt_id'])
+        if puzzle['status'] == 'solved':
+            message = "Puzzle <{}|{}> has been solved!".format(
+                puzzle['channel_url'],
+                puzzle['name'])
+        else:
+            message = "Oops. Puzzle <{}|{}> has been marked unsolved!".format(
+                puzzle['channel_url'],
+                puzzle['name'])
+        slack_send_message(turb.slack_client, hunt['channel_id'], message)
+
     # We need to set the channel topic if any of puzzle name, url,
     # state, status, or solution, has changed. Let's just do that
     # unconditionally here.
@@ -581,7 +603,7 @@ def puzzle(turb, body, args):
                 "Sorry, this channel doesn't appear to be a hunt or a puzzle "
                 + "channel, so the `/puzzle` command cannot work here.")
 
-    blocks = puzzle_blocks(puzzle)
+    blocks = puzzle_blocks(puzzle, include_rounds=True)
 
     requests.post(response_url,
                   json = {'blocks': blocks},