]> git.cworth.org Git - turbot/commitdiff
Rename 'slug' field in hunt table to 'hunt_id'
authorCarl Worth <cworth@cworth.org>
Wed, 21 Oct 2020 18:40:38 +0000 (11:40 -0700)
committerCarl Worth <cworth@cworth.org>
Wed, 21 Oct 2020 18:40:38 +0000 (11:40 -0700)
We were already using the name "Hunt ID" in all user-visibile
interfaces, so there was no good justification for having a totally
different name internally.

turbot/actions.py

index 6763e34f3d453e14a2af6c6035050bfcb8ac199b..911367e2b63d1ff6a3d3d960c2357148d81b0265 100644 (file)
@@ -13,7 +13,9 @@ def new_hunt(turb, payload):
         "submit": { "type": "plain_text", "text": "Create" },
         "blocks": [
             input_block("Hunt name", "name", "Name of the hunt"),
-            input_block("Hunt ID", "slug", "Short hunt ID (no spaces)"),
+            input_block("Hunt ID", "hunt_id",
+                        "Used as puzzle channel prefix "
+                        + "(no spaces nor punctuation)"),
             input_block("Hunt URL", "url", "External URL of hunt",
                         optional=True)
         ],
@@ -37,12 +39,12 @@ def new_hunt_submission(turb, payload):
 
     state = payload['view']['state']['values']
     name = state['name']['name']['value']
-    slug = state['slug']['slug']['value']
+    hunt_id = state['hunt_id']['hunt_id']['value']
     url = state['url']['url']['value']
 
-    # Validate that the slug contains no invalid characters
-    if not re.match(r'[-_a-zA-Z0-9]+$', slug):
-        print("Slug field is invalid. Attmpting to return a clean error.")
+    # Validate that the hunt_id contains no invalid characters
+    if not re.match(r'[-_a-zA-Z0-9]+$', hunt_id):
+        print("Hunt ID field is invalid. Attmpting to return a clean error.")
         return {
             'statusCode': 200,
             'headers': {
@@ -51,14 +53,14 @@ def new_hunt_submission(turb, payload):
             'body': json.dumps({
                 "response_action": "errors",
                 "errors": {
-                    "slug": "Hunt ID can only contain letters, "
+                    "hunt_id": "Hunt ID can only contain letters, "
                     + "numbers, hyphens and underscores"
                 }
             })
         }
 
     # Create a channel for the hunt
-    response = turb.slack_client.conversations_create(name=slug)
+    response = turb.slack_client.conversations_create(name=hunt_id)
 
     if not response['ok']:
         print("Error creating channel for hunt {}: {}"
@@ -71,7 +73,7 @@ def new_hunt_submission(turb, payload):
     channel_id = response['channel']['id']
 
     # Create a sheet for the channel
-    sheet = turbot.sheets.sheets_create(turb, slug)
+    sheet = turbot.sheets.sheets_create(turb, hunt_id)
 
     # Insert the newly-created hunt into the database
     turb.hunts_table = turb.db.Table("hunts")
@@ -80,7 +82,7 @@ def new_hunt_submission(turb, payload):
             'channel_id': channel_id,
             "active": True,
             "name": name,
-            "slug": slug,
+            "hunt_id": hunt_id,
             "url": url,
             "sheet_url": sheet['url']
         }