From c7213abc1b0c3fcb276284dbd9ba23bb44b5f67a Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Sat, 9 Jan 2021 00:00:22 -0800 Subject: [PATCH] Add display of round(s) in /puzzle output Making the output more complete (while still remaining quite compact). --- turbot/interaction.py | 2 +- turbot/puzzle.py | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/turbot/interaction.py b/turbot/interaction.py index 69db521..955fae5 100644 --- a/turbot/interaction.py +++ b/turbot/interaction.py @@ -581,7 +581,7 @@ def puzzle(turb, body, args): "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) + blocks = puzzle_blocks(puzzle, include_rounds=True) requests.post(response_url, json = {'blocks': blocks}, diff --git a/turbot/puzzle.py b/turbot/puzzle.py index f0456c6..b7afc8a 100644 --- a/turbot/puzzle.py +++ b/turbot/puzzle.py @@ -46,7 +46,7 @@ def find_puzzle_for_url(turb, hunt_id, url): return response['Items'][0] -def puzzle_blocks(puzzle): +def puzzle_blocks(puzzle, include_rounds=False): """Generate Slack blocks for a puzzle The puzzle argument should be a dictionary as returned from the @@ -83,10 +83,19 @@ def puzzle_blocks(puzzle): if state: state_str = "\n{}".format(state) - puzzle_text = "{}{} <{}|{}> ({}){}".format( + rounds_str = '' + if include_rounds and 'rounds' in puzzle: + rounds = puzzle['rounds'] + rounds_str = " in round{}: {}".format( + "s" if len(rounds) > 1 else "", + ", ".join(rounds) + ) + + puzzle_text = "{}{} <{}|{}> ({}){}{}".format( status_emoji, solution_str, channel_url(channel_id), name, - ', '.join(links), state_str + ', '.join(links), rounds_str, + state_str ) # Combining hunt ID and puzzle ID together here is safe because -- 2.43.0