]> git.cworth.org Git - turbot/commitdiff
Add a /hunt command
authorCarl Worth <cworth@cworth.org>
Tue, 5 Jan 2021 03:20:27 +0000 (19:20 -0800)
committerCarl Worth <cworth@cworth.org>
Tue, 5 Jan 2021 03:20:27 +0000 (19:20 -0800)
Which spits out details of the current hunt, (in a format very similar
to what appears in the Turbot home view).

turbot/interaction.py

index 359823464f40e5e31de28aa07abc2738bed1ca68..bb09b6854ad6a2fadb88b2923b34c9cc7a3234f5 100644 (file)
@@ -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