# Hunt/Puzzle IDs are restricted to lowercase letters, numbers, and underscores
valid_id_re = r'^[_a-z0-9]+$'
+lambda_ok = {'statusCode': 200}
+
def bot_reply(message):
"""Construct a return value suitable for a bot reply
if (result['ok']):
submission_handlers[result['view']['id']] = new_hunt_submission
- return {
- 'statusCode': 200,
- 'body': 'OK'
- }
+ return lambda_ok
actions['button'] = {"new_hunt": new_hunt}
# Invite the initiating user to the channel
turb.slack_client.conversations_invite(channel=channel_id, users=user_id)
- return {
- 'statusCode': 200,
- }
+ return lambda_ok
def view_submission(turb, payload):
"""Handler for Slack interactive view submission
else:
turb.slack_client.chat_postMessage(channel=channel_id, text=result)
- return {
- 'statusCode': 200,
- 'body': ""
- }
+ return lambda_ok
commands["/rot"] = rot
if (result['ok']):
submission_handlers[result['view']['id']] = puzzle_submission
- return {
- 'statusCode': 200
- }
+ return lambda_ok
commands["/puzzle"] = puzzle
# 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)
}
)
- return {
- 'statusCode': 200
- }
+ return lambda_ok
# XXX: This duplicates functionality eith events.py:set_channel_description
def set_channel_topic(turb, puzzle):
set_channel_topic(turb, puzzle)
+ 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