tidy up error returns
This commit is contained in:
parent
36485fbda8
commit
feb10e85f3
1 changed files with 67 additions and 56 deletions
|
|
@ -17,17 +17,18 @@ def setup(bot: bot.Bot):
|
||||||
|
|
||||||
if not username:
|
if not username:
|
||||||
await ctx.send(u.error_msg("Please provide a Last.fm username (or set yours with `/setfm`)"))
|
await ctx.send(u.error_msg("Please provide a Last.fm username (or set yours with `/setfm`)"))
|
||||||
else:
|
print("returned")
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
user = bot.lastfm.get_user(username)
|
user = bot.lastfm.get_user(username)
|
||||||
track = user.get_now_playing()
|
track = user.get_now_playing()
|
||||||
|
|
||||||
if track == None:
|
if track == None:
|
||||||
now_playing = False
|
now_playing = False
|
||||||
played_track = user.get_recent_tracks(limit=1)
|
played_track = user.get_recent_tracks(limit=1)
|
||||||
track = played_track[0].track
|
track = played_track[0].track
|
||||||
|
else: now_playing = True
|
||||||
else:
|
|
||||||
now_playing = True
|
|
||||||
|
|
||||||
track_url = track.get_url()
|
track_url = track.get_url()
|
||||||
track_name = track.get_name()
|
track_name = track.get_name()
|
||||||
|
|
@ -59,8 +60,12 @@ def setup(bot: bot.Bot):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
await ctx.send(u.error_msg("Unknown database error."))
|
await ctx.send(u.error_msg("Unknown database error."))
|
||||||
if not username: await ctx.send(u.error_msg("Please provide an `artist | album` query or set your Last.fm username with `/setfm`."))
|
|
||||||
else:
|
if not username:
|
||||||
|
await ctx.send(u.error_msg("Please provide an `artist | album` query or set your Last.fm username with `/setfm`."))
|
||||||
|
print("returned")
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
user = bot.lastfm.get_user(username)
|
user = bot.lastfm.get_user(username)
|
||||||
|
|
||||||
|
|
@ -79,16 +84,22 @@ def setup(bot: bot.Bot):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
await ctx.send(u.error_msg(f"Unknown error:\n`{e}`"))
|
await ctx.send(u.error_msg(f"Unknown error:\n`{e}`"))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
if "|" not in album:
|
if "|" not in album:
|
||||||
await ctx.send(u.error_msg("Please search using the format `artist | album name`."))
|
await ctx.send(u.error_msg("Please search using the format `artist | album name`."))
|
||||||
else:
|
print("returned")
|
||||||
|
return
|
||||||
|
|
||||||
artist = ' '.join(album).split(sep="|")[0]
|
artist = ' '.join(album).split(sep="|")[0]
|
||||||
albumtitle = ' '.join(album).split(sep="|")[1]
|
albumtitle = ' '.join(album).split(sep="|")[1]
|
||||||
|
|
||||||
if not artist or not albumtitle:
|
if not artist or not albumtitle:
|
||||||
await ctx.send(u.error_msg("Please enter a valid artist and album name."))
|
await ctx.send(u.error_msg("Please enter a valid artist and album name."))
|
||||||
else:
|
print("returned")
|
||||||
|
return
|
||||||
|
|
||||||
albumobj = bot.lastfm.get_album(artist=artist, title=albumtitle)
|
albumobj = bot.lastfm.get_album(artist=artist, title=albumtitle)
|
||||||
cover_art = albumobj.get_cover_image()
|
cover_art = albumobj.get_cover_image()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue