]> git.cworth.org Git - turbot/commitdiff
At channel creation time, lodge Puzzle and Sheet URLs into channel topic
authorCarl Worth <cworth@cworth.org>
Thu, 22 Oct 2020 22:44:53 +0000 (15:44 -0700)
committerCarl Worth <cworth@cworth.org>
Thu, 22 Oct 2020 22:46:40 +0000 (15:46 -0700)
And the channel description as well, (which isn't as useful but does
appear in some places).

turbot/events.py

index bbec056a985b34bfe73a9202ca7ff955415b4d3c..ca2fd71fa1d9b787fe23aeb19b32527370715c6a 100644 (file)
@@ -184,6 +184,26 @@ def hunt_channel_created(turb, channel_name, channel_id):
 
     return lambda_success
 
+def set_channel_description(turb, puzzle):
+    channel_id = puzzle['channel_id']
+    description = puzzle['name']
+    url = puzzle.get('url', None)
+    sheet_url = puzzle.get('sheet_url', None)
+
+    links = []
+    if url:
+        links.append("<{}|Puzzle>".format(url))
+    if sheet_url:
+        links.append("<{}|Sheet>".format(sheet_url))
+
+    if len(links):
+        description += "({})".format(', '.join(links))
+
+    turb.slack_client.conversations_setPurpose(channel=channel_id,
+                                               purpose=description)
+    turb.slack_client.conversations_setTopic(channel=channel_id,
+                                             topic=description)
+
 def puzzle_channel_created(turb, puzzle_channel_name, puzzle_channel_id):
     """Creates sheet and invites user for a newly-created puzzle channel"""
 
@@ -213,6 +233,9 @@ def puzzle_channel_created(turb, puzzle_channel_name, puzzle_channel_id):
     if not item['url']:
         del item['url']
 
+    # Get the puzzle's name into the channel description
+    set_channel_description(turb, item)
+
     # Before launching into sheet creation, indicate that we're doing this
     # in the database. This way, if we take too long to create the sheet
     # and Slack retries the event, that next event will see this 'pending'
@@ -232,6 +255,9 @@ def puzzle_channel_created(turb, puzzle_channel_name, puzzle_channel_id):
                                        text="Sheet created for this puzzle: {}"
                                        .format(sheet['url']))
 
+    # Get the new sheet_url into the channel description
+    set_channel_description(turb, item)
+
     hunts_table = turb.db.Table('hunts')
     response = hunts_table.scan(
         FilterExpression='hunt_id = :hunt_id',