]> git.cworth.org Git - turbot/commitdiff
Drop the puzzle ID field from the /puzzle dialog
authorCarl Worth <cworth@cworth.org>
Fri, 23 Oct 2020 13:41:41 +0000 (06:41 -0700)
committerCarl Worth <cworth@cworth.org>
Fri, 23 Oct 2020 13:41:41 +0000 (06:41 -0700)
Much easier to just have the bot generate this instead.

turbot/interaction.py

index 180de8b923c175676ef2b0993a38256e966158b1..ab35a395bbdc6fe1020b3d84611865a6bf6db69b 100644 (file)
@@ -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']