From 609130e36ca9ca8642caf618f7b3a50a688f46af Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Mon, 4 Jan 2021 19:20:27 -0800 Subject: [PATCH] Add a /hunt command Which spits out details of the current hunt, (in a format very similar to what appears in the Turbot home view). --- turbot/interaction.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/turbot/interaction.py b/turbot/interaction.py index 3598234..bb09b68 100644 --- a/turbot/interaction.py +++ b/turbot/interaction.py @@ -2,7 +2,7 @@ from slack.errors import SlackApiError from turbot.blocks import ( input_block, section_block, text_block, multi_select_block ) -from turbot.hunt import find_hunt_for_hunt_id +from turbot.hunt import find_hunt_for_hunt_id, hunt_blocks from turbot.puzzle import find_puzzle_for_url import turbot.rot import turbot.sheets @@ -612,3 +612,33 @@ def solved(turb, body, args): 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 -- 2.43.0