add cover command

This commit is contained in:
yuki 2025-10-07 04:57:25 -03:00
parent 0b52404731
commit 71039a4c84
2 changed files with 51 additions and 0 deletions

View file

@ -1,3 +1,5 @@
import requests
import nerimity import nerimity
import pylast import pylast
@ -47,3 +49,33 @@ def setup(bot: bot.Bot):
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."))
@bot.command(name="cover", aliases=["coverart","art"])
@bot.slash_command(name="cover", description="Returns cover art of last played album or a custom query.")
async def cover(ctx: nerimity.Context, *album: str):
username = None
user = None
if not album:
try: username = await bot.get_lastfm(ctx.author.id)
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:
try:
user = bot.lastfm.get_user(username)
if not user.get_now_playing:
last_played = user.get_recent_tracks(limit=1)
album = last_played[0].get_album()
else:
album = user.get_now_playing().get_album()
cover_art = album.get_cover_image()
if not cover_art: await ctx.send(u.error_msg(f"**{album.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}")
except Exception as e:
print(e)
await ctx.send(u.error_msg("Unknown error."))

View file

@ -1,3 +1,22 @@
import requests
import mimetypes
import nerimity
# def construct_attachment_from_url(url: str = None):
# if not url: return None
# content = requests.get(url).content
# attachment = nerimity.Attachment()
# attachment.internal_type = nerimity.AttachmentTypes.OUTGOING
# attachment.data = content
# attachment.data_type, _ = mimetypes.guess_type(url=url)
# attachment.size = len(attachment.data)
# attachment.name = url.split("/")[-1]
# return attachment
def error_msg(message: str): def error_msg(message: str):
return f"[#e5323b][Error] [#reset]{message}" return f"[#e5323b][Error] [#reset]{message}"