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:
|
||||
await ctx.send(u.error_msg("Please provide a Last.fm username (or set yours with `/setfm`)"))
|
||||
else:
|
||||
print("returned")
|
||||
return
|
||||
|
||||
try:
|
||||
user = bot.lastfm.get_user(username)
|
||||
track = user.get_now_playing()
|
||||
|
||||
if track == None:
|
||||
now_playing = False
|
||||
played_track = user.get_recent_tracks(limit=1)
|
||||
track = played_track[0].track
|
||||
|
||||
else:
|
||||
now_playing = True
|
||||
else: now_playing = True
|
||||
|
||||
track_url = track.get_url()
|
||||
track_name = track.get_name()
|
||||
|
|
@ -59,8 +60,12 @@ def setup(bot: bot.Bot):
|
|||
except Exception as e:
|
||||
print(e)
|
||||
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:
|
||||
user = bot.lastfm.get_user(username)
|
||||
|
||||
|
|
@ -79,16 +84,22 @@ def setup(bot: bot.Bot):
|
|||
except Exception as e:
|
||||
print(e)
|
||||
await ctx.send(u.error_msg(f"Unknown error:\n`{e}`"))
|
||||
|
||||
else:
|
||||
try:
|
||||
if "|" not in album:
|
||||
await ctx.send(u.error_msg("Please search using the format `artist | album name`."))
|
||||
else:
|
||||
print("returned")
|
||||
return
|
||||
|
||||
artist = ' '.join(album).split(sep="|")[0]
|
||||
albumtitle = ' '.join(album).split(sep="|")[1]
|
||||
|
||||
if not artist or not albumtitle:
|
||||
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)
|
||||
cover_art = albumobj.get_cover_image()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue