]> git.cworth.org Git - turbot/commitdiff
Create a new Slack channel when creating a hunt
authorCarl Worth <cworth@cworth.org>
Sat, 17 Oct 2020 00:43:31 +0000 (17:43 -0700)
committerCarl Worth <cworth@cworth.org>
Sat, 17 Oct 2020 01:00:47 +0000 (18:00 -0700)
Using the slug of the hunt for the channel name.

Some thoughts on improving this:

  * Should we modify the slug in some way to distinguish this as a
    hunt channel?

  * We should definitely do validation of the legality of the slug for
    a channel name.

  * We should invite the triggering user to the channel

  * We should put the hunt URL into the topic or description

  * Do we want to create a sheet for hunt channels or only for puzzle
    channels?

turbot/actions.py

index 06e2d58195dbb96d281fe828ad69e05af3149237..ca4aa02d48a0899afeab1bedd04ad1651b608739 100644 (file)
@@ -37,10 +37,21 @@ def new_hunt_submission(turb, payload):
     slug = state['slug']['slug']['value']
     url = state['url']['url']['value']
 
-    table = turb.db.Table("hunts")
-    table.put_item(
+    response = turb.slack_client.conversations_create(name=slug)
+
+    if not response['ok']:
+        print("Error creating channel for hunt {}: {}"
+              .format(name, str(response)))
+        return {
+            'statusCode': 400
+        }
+
+    channel_id = response['channel']['id']
+
+    turb.hunts_table = turb.db.Table("hunts")
+    turb.hunts_table.put_item(
         Item={
-            'channel_id': "placeholder-" + str(uuid.uuid4()),
+            'channel_id': channel_id,
             "active": True,
             "name": name,
             "slug": slug,