]> git.cworth.org Git - turbot/commitdiff
Add some feedback to the puzzle's channel when a puzzle is solved
authorCarl Worth <cworth@cworth.org>
Fri, 23 Oct 2020 13:18:54 +0000 (06:18 -0700)
committerCarl Worth <cworth@cworth.org>
Fri, 23 Oct 2020 13:32:27 +0000 (06:32 -0700)
Without this, the '/solved' command felt rather anti-climactic.

turbot/events.py
turbot/interaction.py

index 8a5119d53d9af3f2012e9bd435ab19b55a0b9b88..7a8654e837fad7d6a1cbf447c1fa158fdb907197 100644 (file)
@@ -307,6 +307,4 @@ def channel_created(turb, event):
     else:
         return hunt_channel_created(turb, channel_name, channel_id)
 
-    
-
 events['channel_created'] = channel_created
index 1638b7391eac709d42a84cd40192056d8cc4b777..180de8b923c175676ef2b0993a38256e966158b1 100644 (file)
@@ -7,6 +7,7 @@ import json
 import re
 import requests
 from botocore.exceptions import ClientError
+from turbot.slack import slack_send_message
 
 actions = {}
 commands = {}
@@ -370,10 +371,18 @@ def puzzle_submission(turb, payload, metadata):
 # XXX: This duplicates functionality eith events.py:set_channel_description
 def set_channel_topic(turb, puzzle):
     channel_id = puzzle['channel_id']
-    description = puzzle['name']
+    name = puzzle['name']
     url = puzzle.get('url', None)
     sheet_url = puzzle.get('sheet_url', None)
     state = puzzle.get('state', None)
+    status = puzzle['status']
+
+    description = ''
+
+    if status == 'solved':
+        description += "Solved: `{}` ".format('`, `'.join(puzzle['solution']))
+
+    description += name
 
     links = []
     if url:
@@ -421,6 +430,7 @@ def solved(turb, body, args):
 
     channel_id = body['channel_id'][0]
     channel_name = body['channel_name'][0]
+    user_name = body['user_name'][0]
 
     (puzzle, table) = channel_is_puzzle(turb, channel_id, channel_name)
 
@@ -432,6 +442,14 @@ def solved(turb, body, args):
     puzzle['solution'].append(args)
     table.put_item(Item=puzzle)
 
+    # Report the solution to the puzzle's channel
+    slack_send_message(
+        turb.slack_client, channel_id,
+        "Puzzle mark solved by {}: `{}`".format(user_name, args))
+
+    # And update the puzzle's description
+    set_channel_topic(turb, puzzle)
+
     return lambda_ok
 
 commands["/solved"] = solved