mirror of
https://github.com/MrDetonia/Maki.git
synced 2024-11-22 11:54:16 -05:00
v0.19.2 except index error parsing last.fm json
This commit is contained in:
parent
1d3ed4247d
commit
3cb3d856ad
7
bot.py
7
bot.py
@ -31,7 +31,7 @@ from secret import token, lfmkey
|
|||||||
# CONFIGURATION
|
# CONFIGURATION
|
||||||
|
|
||||||
# bot version
|
# bot version
|
||||||
version = "v0.19.1"
|
version = "v0.19.2"
|
||||||
|
|
||||||
# text shown by .help command
|
# text shown by .help command
|
||||||
helptext = """I am a Discord bot written in Python
|
helptext = """I am a Discord bot written in Python
|
||||||
@ -101,15 +101,18 @@ def lastfm_np(username):
|
|||||||
|
|
||||||
# check we got a valid response
|
# check we got a valid response
|
||||||
if 'error' in np:
|
if 'error' in np:
|
||||||
return "Couldn't get last.fm data for " + username
|
return "I couldn't get last.fm data for " + username
|
||||||
|
|
||||||
# get fields
|
# get fields
|
||||||
|
try:
|
||||||
username = np['recenttracks']['@attr']['user']
|
username = np['recenttracks']['@attr']['user']
|
||||||
track = np['recenttracks']['track'][0]
|
track = np['recenttracks']['track'][0]
|
||||||
album = track['album']['#text']
|
album = track['album']['#text']
|
||||||
artist = track['artist']['#text']
|
artist = track['artist']['#text']
|
||||||
song = track['name']
|
song = track['name']
|
||||||
nowplaying = '@attr' in track
|
nowplaying = '@attr' in track
|
||||||
|
except IndexError:
|
||||||
|
return "It looks like " + username + " hasn't played anything recently."
|
||||||
|
|
||||||
# grammar
|
# grammar
|
||||||
if album != "":
|
if album != "":
|
||||||
|
Loading…
Reference in New Issue
Block a user