Fix !uptime when not streaming

This commit is contained in:
Anthony Sottile 2019-03-06 17:31:25 -08:00
parent 3644a5b8fc
commit 6ee4331129
1 changed files with 5 additions and 1 deletions

6
bot.py
View File

@ -131,7 +131,11 @@ class UptimeResponse(Response):
async with aiohttp.ClientSession() as session: async with aiohttp.ClientSession() as session:
async with session.get(url, headers=headers) as response: async with session.get(url, headers=headers) as response:
text = await response.text() text = await response.text()
start_time_s = json.loads(text)['data'][0]['started_at'] data = json.loads(text)['data']
if not data:
msg = 'not currently streaming!'
return PRIVMSG.format(channel=config.channel, msg=msg)
start_time_s = data[0]['started_at']
start_time = datetime.datetime.strptime( start_time = datetime.datetime.strptime(
start_time_s, '%Y-%m-%dT%H:%M:%SZ', start_time_s, '%Y-%m-%dT%H:%M:%SZ',
) )