From d55e2ff3c94a7c92a89b93510a63c5c15378723a Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Fri, 23 Oct 2020 06:18:54 -0700 Subject: [PATCH] Add some feedback to the puzzle's channel when a puzzle is solved Without this, the '/solved' command felt rather anti-climactic. --- turbot/events.py | 2 -- turbot/interaction.py | 20 +++++++++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/turbot/events.py b/turbot/events.py index 8a5119d..7a8654e 100644 --- a/turbot/events.py +++ b/turbot/events.py @@ -307,6 +307,4 @@ def channel_created(turb, event): else: return hunt_channel_created(turb, channel_name, channel_id) - - events['channel_created'] = channel_created diff --git a/turbot/interaction.py b/turbot/interaction.py index 1638b73..180de8b 100644 --- a/turbot/interaction.py +++ b/turbot/interaction.py @@ -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 -- 2.43.0