]> git.cworth.org Git - turbot/commitdiff
Add new /puzzle command which simply prints the current puzzle
authorCarl Worth <cworth@cworth.org>
Sat, 9 Jan 2021 07:51:32 +0000 (23:51 -0800)
committerCarl Worth <cworth@cworth.org>
Sat, 9 Jan 2021 07:54:06 +0000 (23:54 -0800)
This is the same format one could get from the /hunt command, but
limited to the current puzzle. This is a very convenient way to see
all the puzzle fields and to get access to the pencil button to edit
the current puzzle.

TODO
turbot/interaction.py

diff --git a/TODO b/TODO
index 2c77ac8fdd152a716b4fe8845ba1ebb35ad569b4..23db9cb69f82b16b08763accc5e279f3bac83271 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,8 +1,6 @@
 Ordered punch-list (aiming to complete by 2021-01-08)
 -----------------------------------------------------
 
-• Add new /puzzle giving puzzle status (and including :pencil:)
-
 • Put a message in the puzzle channel when a user edits something
   (maybe just spit out the /puzzle output)
 
index bbaa51d1fd862e2e38183c1e1219d3e7ee321cdf..69db52149d1eda35e3a62fda6b70b1184e0476ba 100644 (file)
@@ -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
@@ -549,13 +550,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)
+
+    requests.post(response_url,
+                  json = {'blocks': blocks},
+                  headers = {'Content-type': 'application/json'}
+                  )
+
+    return lambda_ok
 
 commands["/puzzle"] = puzzle