X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=turbot%2Finteraction.py;h=f634cbcdadf6120af0787f194883a573eb2cbdf8;hb=9b570c69c799bc2442d712507474c803f7a571bf;hp=947a01f67a48fee942f672551bd03f196dcdad2e;hpb=41931beb0de72a0669600e92dfe4d00b2e596dbf;p=turbot diff --git a/turbot/interaction.py b/turbot/interaction.py index 947a01f..f634cbc 100644 --- a/turbot/interaction.py +++ b/turbot/interaction.py @@ -6,6 +6,7 @@ import turbot.slack import json import re import requests +from botocore.exceptions import ClientError TURBOT_USER_ID = 'U01B9QM4P9R' @@ -95,6 +96,33 @@ def new_hunt_submission(turb, payload, metadata): "Hunt ID can only contain letters, " + "numbers, and underscores") + # Check to see if the hunts table exists + hunts_table = turb.db.Table("hunts") + + try: + exists = hunts_table.table_status in ("CREATING", "UPDATING", + "ACTIVE") + except ClientError: + exists = False + + # Create the hunts table if necessary. + if not exists: + hunts_table = turb.db.create_table( + TableName='hunts', + KeySchema=[ + {'AttributeName': 'channel_id', 'KeyType': 'HASH'}, + ], + AttributeDefinitions=[ + {'AttributeName': 'channel_id', 'AttributeType': 'S'}, + ], + ProvisionedThroughput={ + 'ReadCapacityUnits': 5, + 'WriteCapacityUnits': 5 + } + ) + return submission_error("hunt_id", + "Still bootstrapping hunts table. Try again.") + # Create a channel for the hunt try: response = turb.slack_client.conversations_create(name=hunt_id) @@ -114,8 +142,9 @@ def new_hunt_submission(turb, payload, metadata): # Create a sheet for the channel sheet = turbot.sheets.sheets_create(turb, hunt_id) + channel_id = response['channel']['id'] + # Insert the newly-created hunt into the database - hunts_table = turb.db.Table("hunts") hunts_table.put_item( Item={ 'channel_id': channel_id,