From 787acd659f83b5bd42a1c9c3776c253ac9be4d56 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Thu, 22 Oct 2020 15:44:53 -0700 Subject: [PATCH] At channel creation time, lodge Puzzle and Sheet URLs into channel topic And the channel description as well, (which isn't as useful but does appear in some places). --- turbot/events.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/turbot/events.py b/turbot/events.py index bbec056..ca2fd71 100644 --- a/turbot/events.py +++ b/turbot/events.py @@ -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', -- 2.43.0