X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=turbot%2Finteraction.py;h=c1064bfa22cfb2d6e4341163480e5ea1d3edc0b4;hb=f01639c9b18dabbc5eb1c659ea871c3cda6ea727;hp=f50a83495fee11761a27bcd3f1051ced3b493d35;hpb=4778050b2bde391905712345b88f77616f4cc378;p=turbot diff --git a/turbot/interaction.py b/turbot/interaction.py index f50a834..c1064bf 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 @@ -1033,6 +1052,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