- item['sheet_url'] = sheet['url']
- puzzle_table.put_item(Item=item)
-
- # Message the channel with the URL of the puzzle's sheet
- turb.slack_client.chat_postMessage(channel=puzzle_channel_id,
- text="Sheet created for this puzzle: {}"
- .format(sheet['url']))
-
- hunts_table = turb.db.Table('hunts')
- response = hunts_table.scan(
- FilterExpression='hunt_id = :hunt_id',
- ExpressionAttributeValues={':hunt_id': hunt_id}
+ puzzle['sheet_url'] = sheet['url']
+ turb.table.put_item(Item=puzzle)
+
+ # Get the new sheet_url into the channel topic and description
+ set_channel_topic_and_description(turb, puzzle)
+
+ # Lookup and invite all users from this hunt to this new puzzle
+
+ # Find all members of the hunt channel
+ members = slack_channel_members(turb.slack_client, hunt['channel_id'])
+
+ # Filter out Turbot's own ID to avoid inviting itself
+ # has opted out of being auto-invited
+ members = [m for m in members if m != TURBOT_USER_ID]
+
+ slack_send_message(
+ turb.slack_client, channel_id,
+ "Inviting all members from the hunt channel: "
+ + "<#{}>".format(hunt['channel_id']))
+
+ # Invite those members to the puzzle channel (in chunks of 500)
+ cursor = 0
+ while cursor < len(members):
+ turb.slack_client.conversations_invite(
+ channel=channel_id,
+ users=members[cursor:cursor + 500])
+ cursor += 500
+
+ # And finally, give a welcome message with some documentation
+ # on how to update the state of the puzzle in the database.
+ welcome_msg = (
+ "Welcome! This channel is the primary place to "
+ + "discuss things as the team works together to solve the "
+ + "puzzle \"{}\". ".format(puzzle['name'])