From: Carl Worth Date: Fri, 23 Oct 2020 13:41:41 +0000 (-0700) Subject: Drop the puzzle ID field from the /puzzle dialog X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=a22c3fcd19986ee27219381716cbfcd105267581;hp=d55e2ff3c94a7c92a89b93510a63c5c15378723a;p=turbot Drop the puzzle ID field from the /puzzle dialog Much easier to just have the bot generate this instead. --- diff --git a/turbot/interaction.py b/turbot/interaction.py index 180de8b..ab35a39 100644 --- a/turbot/interaction.py +++ b/turbot/interaction.py @@ -302,9 +302,6 @@ def puzzle(turb, body, args): "blocks": [ section_block(text_block("*For {}*".format(hunt_name))), input_block("Puzzle name", "name", "Name of the puzzle"), - input_block("Puzzle ID", "puzzle_id", - "Used as part of channel name " - + "(no spaces nor punctuation)"), input_block("Puzzle URL", "url", "External URL of puzzle", optional=True) ] @@ -331,14 +328,10 @@ def puzzle_submission(turb, payload, metadata): state = payload['view']['state']['values'] name = state['name']['name']['value'] - puzzle_id = state['puzzle_id']['puzzle_id']['value'] url = state['url']['url']['value'] - # 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") + # Create a Slack-channel-safe puzzle_id + puzzle_id = re.sub(r'[^a-zA-Z0-9_]', '', name).lower() # Create a channel for the puzzle hunt_dash_channel = "{}-{}".format(hunt_id, puzzle_id) @@ -347,9 +340,10 @@ def puzzle_submission(turb, payload, metadata): response = turb.slack_client.conversations_create( name=hunt_dash_channel) except SlackApiError as e: - return submission_error("puzzle_id", - "Error creating Slack channel: {}" - .format(e.response['error'])) + return submission_error( + "name", + "Error creating Slack channel {}: {}" + .format(hunt_dash_channel, e.response['error'])) puzzle_channel_id = response['channel']['id']