+
+def solved(turb, body, args):
+ """Implementation of the /solved command
+
+ The args string should be a confirmed solution."""
+
+ channel_id = body['channel_id'][0]
+ user_name = body['user_name'][0]
+
+ puzzle = puzzle_for_channel(turb, channel_id)
+
+ if not puzzle:
+ return bot_reply("Sorry, this is not a puzzle channel.")
+
+ if not args:
+ return bot_reply(
+ "Error, no solution provided. Usage: `/solved SOLUTION HERE`")
+
+ # Set the status and solution fields in the database
+ puzzle['status'] = 'solved'
+ puzzle['solution'].append(args)
+ if 'state' in puzzle:
+ del puzzle['state']
+ turb.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))
+
+ # Also report the solution to the hunt channel
+ hunt = find_hunt_for_hunt_id(turb, puzzle['hunt_id'])
+ slack_send_message(
+ turb.slack_client, hunt['channel_id'],
+ "Puzzle <{}|{}> has been solved!".format(
+ puzzle['channel_url'],
+ puzzle['name'])
+ )
+
+ # And update the puzzle's description
+ set_channel_topic(turb, puzzle)
+
+ # And rename the sheet to prefix with "SOLVED: "
+ turbot.sheets.renameSheet(turb, puzzle['sheet_url'],
+ 'SOLVED: ' + puzzle['name'])
+
+ # Finally, rename the Slack channel to add the suffix '-solved'
+ channel_name = "{}-{}-solved".format(
+ puzzle['hunt_id'],
+ puzzle['puzzle_id'])
+ turb.slack_client.conversations_rename(
+ channel=puzzle['channel_id'],
+ name=channel_name)
+
+ return lambda_ok
+
+commands["/solved"] = solved
+
+
+def hunt(turb, body, args):
+ """Implementation of the /hunt command
+
+ The (optional) args string should be one of 'all', 'solved', or
+ 'unsolved' to indicate which set of puzzles should be
+ displayed. If omitted, this command will default to showing only
+ unsolved puzzles.
+ """
+
+ channel_id = body['channel_id'][0]
+ response_url = body['response_url'][0]
+
+ hunt = hunt_for_channel(turb, channel_id)
+
+ if not hunt:
+ return bot_reply("Sorry, this channel doesn't appear to "
+ + "be a hunt or puzzle channel")
+
+ blocks = hunt_blocks(turb, hunt)
+
+ requests.post(response_url,
+ json = { 'blocks': blocks },
+ headers = {'Content-type': 'application/json'}
+ )
+
+ return lambda_ok
+
+commands["/hunt"] = hunt