]> git.cworth.org Git - turbot/blobdiff - turbot/interaction.py
Add an implementation of the /solved command
[turbot] / turbot / interaction.py
index 566a3d83caa287bbe5c6cee94d80058f69a6b808..20b2d7db820df0fd7b7a3242cc2e215e769cf26e 100644 (file)
@@ -334,8 +334,8 @@ def puzzle_submission(turb, payload, metadata):
     # Validate that the puzzle_id contains no invalid characters
     if not re.match(valid_id_re, puzzle_id):
         return submission_error("puzzle_id",
-                                "Puzzle ID can only contain lowercase letters, "
-                                + "numbers, and underscores")
+                                "Puzzle ID can only contain lowercase letters,"
+                                + " numbers, and underscores")
 
     # Create a channel for the puzzle
     hunt_dash_channel = "{}-{}".format(hunt_id, puzzle_id)
@@ -411,3 +411,25 @@ def state(turb, body, args):
     return lambda_ok
 
 commands["/state"] = state
+
+def solved(turb, body, args):
+    """Implementation of the /solved command
+
+    The args string should be a confirmed solution."""
+
+    channel_id = body['channel_id'][0]
+    channel_name = body['channel_name'][0]
+
+    (puzzle, table) = channel_is_puzzle(turb, channel_id, channel_name)
+
+    if not puzzle:
+        return bot_reply("Sorry, this is not a puzzle channel.")
+
+    # Set the status and solution fields in the database
+    puzzle['status'] = 'solved'
+    puzzle['solution'].append(args)
+    table.put_item(Item=puzzle)
+
+    return lambda_ok
+
+commands["/solved"] = solved