"Hunt ID can only contain lowercase letters, "
+ "numbers, and underscores")
- # Check to see if the hunts table exists
- hunts_table = turb.db.Table("hunts")
-
+ # Check to see if the turbot table exists
try:
- exists = hunts_table.table_status in ("CREATING", "UPDATING",
- "ACTIVE")
+ exists = turb.table.table_status in ("CREATING", "UPDATING",
+ "ACTIVE")
except ClientError:
exists = False
- # Create the hunts table if necessary.
+ # Create the turbot table if necessary.
if not exists:
- hunts_table = turb.db.create_table(
- TableName='hunts',
+ turb.table = turb.db.create_table(
+ TableName='turbot',
KeySchema=[
- {'AttributeName': 'channel_id', 'KeyType': 'HASH'},
+ {'AttributeName': 'PK', 'KeyType': 'HASH'},
+ {'AttributeName': 'SK', 'KeyType': 'RANGE'},
],
AttributeDefinitions=[
+ {'AttributeName': 'PK', 'AttributeType': 'S'},
+ {'AttributeName': 'SK', 'AttributeType': 'S'},
{'AttributeName': 'channel_id', 'AttributeType': 'S'},
+ {'AttributeName': 'hunt_id', 'AttributeType': 'S'},
],
ProvisionedThroughput={
'ReadCapacityUnits': 5,
'WriteCapacityUnits': 5
- }
+ },
+ GlobalSecondaryIndexes=[
+ {
+ 'IndexName': 'channel_id_index',
+ 'KeySchema': [
+ {'AttributeName': 'channel_id', 'KeyType': 'HASH'}
+ ],
+ 'Projection': {
+ 'ProjectionType': 'ALL'
+ },
+ 'ProvisionedThroughput': {
+ 'ReadCapacityUnits': 5,
+ 'WriteCapacityUnits': 5
+ }
+ },
+ {
+ 'IndexName': 'hunt_id_index',
+ 'KeySchema': [
+ {'AttributeName': 'hunt_id', 'KeyType': 'HASH'}
+ ],
+ 'Projection': {
+ 'ProjectionType': 'ALL'
+ },
+ 'ProvisionedThroughput': {
+ 'ReadCapacityUnits': 5,
+ 'WriteCapacityUnits': 5
+ }
+ }
+ ]
)
return submission_error("hunt_id",
- "Still bootstrapping hunts table. Try again.")
+ "Still bootstrapping turbot table. Try again.")
# Create a channel for the hunt
try:
# 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(
+ turb.table.put_item(
Item={
- 'channel_id': channel_id,
+ "PK": "hunt-{}".format(hunt_id),
+ "SK": "hunt-{}".format(hunt_id),
+ "hunt_id": hunt_id,
+ "channel_id": channel_id,
"active": False,
"name": name,
- "hunt_id": hunt_id,
"url": url
}
)
Returns a dict (filled with database entries) if there is a hunt
for this channel, otherwise returns None."""
- return get_table_item(turb, "hunts", 'channel_id', channel_id)
+ return get_table_item(turb, "channel_id_index", 'channel_id', channel_id)
def find_hunt_for_hunt_id(turb, hunt_id):
"""Given a hunt ID find the database for for that hunt
(channel_id, active, hunt_id, name, url, sheet_url, etc.).
"""
- hunts_table = turb.db.Table("hunts")
+ turbot_table = turb.db.Table("turbot")
- response = hunts_table.scan(
- FilterExpression='hunt_id = :hunt_id',
- ExpressionAttributeValues={':hunt_id': hunt_id}
- )
-
- if 'Items' in response and len(response['Items']):
- item = response['Items'][0]
- return item
+ response = turbot_table.get_item(Key={'PK': 'hunt-{}'.format(hunt_id)})
- return None
+ if 'Item' in response:
+ return response['Item']
+ else:
+ return None
def find_hunt_for_channel(turb, channel_id, channel_name):
"""Given a channel ID/name find the id/name of the hunt for this channel
hunt = find_hunt_for_hunt_id(turb, puzzle['hunt_id'])
slack_send_message(
turb.slack_client, hunt['channel_id'],
- "Puzzle '<{}|{}>' has been solved!".format(
+ "Puzzle <{}|{}> has been solved!".format(
puzzle['channel_url'],
puzzle['name'])
)
set_channel_topic(turb, puzzle)
# And rename the sheet to prefix with "SOLVED: "
- turbot.sheets.renameSheet(turb, puzzle['sheet_url'], 'SOLVED: ' + puzzle['name'])
+ turbot.sheets.renameSheet(turb, puzzle['sheet_url'],
+ 'SOLVED: ' + puzzle['name'])
# Finally, rename the Slack channel to add the suffix '-solved'
channel_name = "{}-{}-solved".format(