add query processing to cover command
This commit is contained in:
parent
71039a4c84
commit
cc088583f1
1 changed files with 32 additions and 7 deletions
|
|
@ -60,22 +60,47 @@ 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`."))
|
if not username: await ctx.send(u.error_msg("Please provide an `artist | album` query or set your Last.fm username with `/setfm`."))
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
user = bot.lastfm.get_user(username)
|
user = bot.lastfm.get_user(username)
|
||||||
|
|
||||||
if not user.get_now_playing:
|
if not user.get_now_playing:
|
||||||
last_played = user.get_recent_tracks(limit=1)
|
last_played = user.get_recent_tracks(limit=1)
|
||||||
album = last_played[0].get_album()
|
albumobj = last_played[0].get_album()
|
||||||
else:
|
else:
|
||||||
album = user.get_now_playing().get_album()
|
albumobj = user.get_now_playing().get_album()
|
||||||
|
|
||||||
cover_art = album.get_cover_image()
|
cover_art = albumobj.get_cover_image()
|
||||||
|
|
||||||
if not cover_art: await ctx.send(u.error_msg(f"**{album.get_name()}** does not seem to have cover art."))
|
if not cover_art: await ctx.send(u.error_msg(f"**{albumobj.get_name()}** does not seem to have cover art."))
|
||||||
else: await ctx.send(f"Here's the cover art for **[{album.get_name()}]({album.get_url()})**:\n{cover_art}")
|
else: await ctx.send(f"Here's the cover art for **[{albumobj.get_name()}]({albumobj.get_url()})**:\
|
||||||
|
{cover_art}")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
await ctx.send(u.error_msg("Unknown error."))
|
await ctx.send(u.error_msg("Unknown error."))
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
if "|" not in album:
|
||||||
|
await ctx.send(u.error_msg("Please search using the format `artist | album name`."))
|
||||||
|
else:
|
||||||
|
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:
|
||||||
|
albumobj = bot.lastfm.get_album(artist=artist, title=albumtitle)
|
||||||
|
cover_art = albumobj.get_cover_image()
|
||||||
|
|
||||||
|
if not cover_art: await ctx.send(u.error_msg(f"**{albumobj.get_name()}** does not seem to have cover art."))
|
||||||
|
else: await ctx.send(
|
||||||
|
f"Here's the cover art for **[{albumobj.get_name(properly_capitalized=True)}]({albumobj.get_url()})**:\
|
||||||
|
{cover_art}"
|
||||||
|
)
|
||||||
|
except pylast.WSError as e:
|
||||||
|
print(e)
|
||||||
|
await ctx.send(u.error_msg(e))
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
await ctx.send(u.error_msg("Unknown parsing error."))
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue