Compare commits
3 commits
4fa08e9e97
...
cc088583f1
| Author | SHA1 | Date | |
|---|---|---|---|
| cc088583f1 | |||
| 71039a4c84 | |||
| 0b52404731 |
3 changed files with 78 additions and 1 deletions
|
|
@ -8,7 +8,8 @@ def setup(bot: bot.Bot):
|
|||
@bot.slash_command(name="setfm", description="Sets your Last.fm username.")
|
||||
async def setfm(ctx: nerimity.Context, username: str = None):
|
||||
if not username:
|
||||
await ctx.send(u.error_msg("Please provide your Last.fm username."))
|
||||
await ctx.send(u.error_msg("Please provide your Last.fm username.\n\
|
||||
usage: `/fm <your last.fm username>`"))
|
||||
else:
|
||||
try:
|
||||
await bot.set_lastfm(ctx.author.id, username)
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import requests
|
||||
|
||||
import nerimity
|
||||
import pylast
|
||||
|
||||
|
|
@ -47,3 +49,58 @@ def setup(bot: bot.Bot):
|
|||
except Exception as e:
|
||||
print(e)
|
||||
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)
|
||||
albumobj = last_played[0].get_album()
|
||||
else:
|
||||
albumobj = user.get_now_playing().get_album()
|
||||
|
||||
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()}]({albumobj.get_url()})**:\
|
||||
{cover_art}")
|
||||
|
||||
except Exception as e:
|
||||
print(e)
|
||||
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."))
|
||||
|
|
|
|||
19
utils.py
19
utils.py
|
|
@ -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):
|
||||
return f"[#e5323b][Error] [#reset]{message}"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue