X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=turbot%2Finteraction.py;h=77a13ee17de4458cd2b59f3d6462ee08cb9d9488;hb=eef8d8d3e4eb8948cf832906f6c83133e93554d2;hp=ec64706658f3126bfc1974921d12e4cdece78ffe;hpb=2dd1171d23caf8fcc739541bfad22d3805a094a9;p=turbot diff --git a/turbot/interaction.py b/turbot/interaction.py index ec64706..77a13ee 100644 --- a/turbot/interaction.py +++ b/turbot/interaction.py @@ -112,8 +112,6 @@ def edit_puzzle_command(turb, body): return edit_puzzle(turb, puzzle, trigger_id) - return lambda_ok - def edit_puzzle_button(turb, payload): """Handler for the action of user pressing an edit_puzzle button""" @@ -339,9 +337,30 @@ def edit_puzzle_submission(turb, payload, metadata): return lambda_ok -def new_hunt(turb, payload): +def new_hunt_command(turb, body): + """Implementation of the '/hunt new' command + + As dispatched from the hunt() function. + """ + + trigger_id = body['trigger_id'][0] + + return new_hunt(turb, trigger_id) + +def new_hunt_button(turb, payload): """Handler for the action of user pressing the new_hunt button""" + trigger_id = payload['trigger_id'] + + return new_hunt(turb, trigger_id) + +def new_hunt(turb, trigger_id): + """Common code for implementing a new hunt dialog + + This implementation is common whether the operations was invoked + by a button (new_hunt_button) or a command (new_hunt_command). + """ + view = { "type": "modal", "private_metadata": json.dumps({}), @@ -357,7 +376,7 @@ def new_hunt(turb, payload): ], } - result = turb.slack_client.views_open(trigger_id=payload['trigger_id'], + result = turb.slack_client.views_open(trigger_id=trigger_id, view=view) if (result['ok']): submission_handlers[result['view']['id']] = new_hunt_submission @@ -686,7 +705,7 @@ def puzzle(turb, body, args): # For a meta puzzle, also display the titles and solutions for all # puzzles in the same round. - if puzzle['type'] == 'meta': + if puzzle.get('type', 'plain') == 'meta': puzzles = hunt_puzzles_for_hunt_id(turb, puzzle['hunt_id']) # Drop this puzzle itself from the report @@ -714,11 +733,20 @@ commands["/puzzle"] = puzzle def new(turb, body, args): """Implementation of the `/new` command - To create a new puzzle. + This can be used to create a new hunt ("/new hunt") or a new + puzzle ("/new puzzle" or simply "/new"). So puzzle creation is the + default behavior (as it is much more common). - This is simply a shortcut for `/puzzle new`. + This operations are identical to the existing "/hunt new" and + "/puzzle new". I don't know that that redundancy is actually + helpful in the interface. But at least having both allows us to + experiment and decide which is more natural and should be kept + around long-term. """ + if args == 'hunt': + return new_hunt_command(turb, body) + return new_puzzle(turb, body) commands["/new"] = new @@ -927,8 +955,8 @@ def tag(turb, body, args): tag = tag.upper() # Reject a tag that is not alphabetic or underscore A-Z_ - if not re.match(r'^[A-Z_]*$', tag): - return bot_reply("Sorry, tags can only contain letters " + if not re.match(r'^[A-Z0-9_]*$', tag): + return bot_reply("Sorry, tags can only contain letters, numbers, " + "and the underscore character.") if action == 'remove': @@ -1033,6 +1061,10 @@ def hunt(turb, body, args): channel_id = body['channel_id'][0] response_url = body['response_url'][0] + # First, farm off "/hunt new" as a separate command + if args == "new": + return new_hunt_command(turb, body) + terms = None if args: # The first word can be a puzzle status and all remaining word