From 2e5bec87f32fb9cba294cbc7c63bb155e3825ebe Mon Sep 17 00:00:00 2001
From: Carl Worth <cworth@cworth.org>
Date: Sat, 9 Jan 2021 00:32:18 -0800
Subject: [PATCH] Report change in a puzzle's solved status to the main hunt
 channel

We were already doing this from the /solved command but now we do it
for puzzle edits as well.
---
 turbot/interaction.py | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/turbot/interaction.py b/turbot/interaction.py
index e68aa6f..bfb759a 100644
--- a/turbot/interaction.py
+++ b/turbot/interaction.py
@@ -247,6 +247,19 @@ def edit_puzzle_submission(turb, payload, metadata):
         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.
-- 
2.45.2