X-Git-Url: https://git.cworth.org/git?p=turbot;a=blobdiff_plain;f=turbot%2Finteraction.py;h=bfb759ada53f9395ac0f8c629ec0fd0991a4b55f;hp=bbaa51d1fd862e2e38183c1e1219d3e7ee321cdf;hb=2e5bec87f32fb9cba294cbc7c63bb155e3825ebe;hpb=886cb3f4f96ac644b90df1b979ee7a9345eb2515 diff --git a/turbot/interaction.py b/turbot/interaction.py index bbaa51d..bfb759a 100644 --- a/turbot/interaction.py +++ b/turbot/interaction.py @@ -7,7 +7,8 @@ from turbot.puzzle import ( find_puzzle_for_url, find_puzzle_for_puzzle_id, puzzle_update_channel_and_sheet, - puzzle_id_from_name + puzzle_id_from_name, + puzzle_blocks ) import turbot.rot import turbot.sheets @@ -178,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'] @@ -237,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. @@ -549,13 +572,45 @@ def puzzle(turb, body, args): The args string can be a sub-command: /puzzle new: Bring up a dialog to create a new puzzle + + Or with no argument at all: + + /puzzle: Print details of the current puzzle (if in a puzzle channel) """ if args == 'new': return new_puzzle(turb, body) - return bot_reply("Unknown syntax for `/puzzle` command. " + - "Use `/puzzle new` to create a new puzzle.") + if len(args): + return bot_reply("Unknown syntax for `/puzzle` command. " + + "Use `/puzzle new` to create a new puzzle.") + + # For no arguments we print the current puzzle as a reply + channel_id = body['channel_id'][0] + response_url = body['response_url'][0] + + puzzle = puzzle_for_channel(turb, channel_id) + + if not puzzle: + hunt = hunt_for_channel(turb, channel_id) + if hunt: + return bot_reply( + "This is not a puzzle channel, but is a hunt channel. " + + "If you want to create a new puzzle for this hunt, use " + + "`/puzzle new`.") + else: + return bot_reply( + "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, include_rounds=True) + + requests.post(response_url, + json = {'blocks': blocks}, + headers = {'Content-type': 'application/json'} + ) + + return lambda_ok commands["/puzzle"] = puzzle