import requests
from botocore.exceptions import ClientError
-TURBOT_USER_ID = 'U01B9QM4P9R'
-
actions = {}
commands = {}
submission_handlers = {}
function above."""
state = payload['view']['state']['values']
+ user_id = payload['user']['id']
name = state['name']['name']['value']
hunt_id = state['hunt_id']['hunt_id']['value']
url = state['url']['url']['value']
"Error creating Slack channel: {}"
.format(e.response['error']))
- if not response['ok']:
- return submission_error("name",
- "Error occurred creating Slack channel "
- + "(see CloudWatch log")
-
- user_id = payload['user']['id']
channel_id = response['channel']['id']
# Create a sheet for the channel
channel_id = response['channel']['id']
# Insert the newly-created hunt into the database
+ # (leaving it as non-active for now until the channel-created handler
+ # finishes fixing it up with a sheet and a companion table)
hunts_table.put_item(
Item={
'channel_id': channel_id,
- "active": True,
+ "active": False,
"name": name,
"hunt_id": hunt_id,
- "url": url,
- "sheet_url": sheet['url']
+ "url": url
}
)
# Invite the initiating user to the channel
turb.slack_client.conversations_invite(channel=channel_id, users=user_id)
- # Message the channel with the URL of the sheet
- turb.slack_client.chat_postMessage(channel=channel_id,
- text="Sheet created for this hunt: {}"
- .format(sheet['url']))
-
- # Create a database table for this hunt's puzzles
- table = turb.db.create_table(
- TableName=hunt_id,
- AttributeDefinitions=[
- {'AttributeName': 'channel_id', 'AttributeType': 'S'}
- ],
- KeySchema=[
- {'AttributeName': 'channel_id', 'KeyType': 'HASH'}
- ],
- ProvisionedThroughput={
- 'ReadCapacityUnits': 5,
- 'WriteCapacityUnits': 4
- }
- )
-
- # Message the hunt channel that the database is ready
- turb.slack_client.chat_postMessage(
- channel=channel_id,
- text="Welcome to your new hunt! "
- + "Use `/puzzle` to create puzzles for the hunt.")
-
return {
'statusCode': 200,
}
This is the modal view presented to the user by the puzzle function
above."""
- print("In puzzle_submission\npayload is: {}\nmetadata is {}"
- .format(payload, metadata))
-
meta = json.loads(metadata)
hunt_id = meta['hunt_id']
hunt_channel_id = meta['hunt_channel_id']
puzzle_channel_id = response['channel']['id']
- # Create a sheet for the puzzle
- sheet = turbot.sheets.sheets_create_for_puzzle(turb, hunt_dash_channel)
-
# Insert the newly-created puzzle into the database
table = turb.db.Table(hunt_id)
-
table.put_item(
Item={
"channel_id": puzzle_channel_id,
"name": name,
"puzzle_id": puzzle_id,
"url": url,
- "sheet_url": sheet['url']
}
)
- # Find all members of the hunt channel
- members = turbot.slack.slack_channel_members(turb.slack_client,
- hunt_channel_id)
-
- # Filter out Turbot's own ID to avoid inviting itself
- members = [m for m in members if m != TURBOT_USER_ID]
-
- turb.slack_client.chat_postMessage(channel=puzzle_channel_id,
- text="Inviting members: {}".format(str(members)))
-
- # Invite those members to the puzzle channel (in chunks of 500)
- cursor = 0
- while cursor < len(members):
- turb.slack_client.conversations_invite(
- channel=puzzle_channel_id,
- users=members[cursor:cursor + 500])
- cursor += 500
-
- # 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']))
return {
'statusCode': 200
}