Compare commits
No commits in common. "cc088583f1963976f4ec974ad8ba9549bc17fa22" and "4fa08e9e97d3370e6ce8ea9b38aac06e21883ba0" have entirely different histories.
cc088583f1
...
4fa08e9e97
3 changed files with 1 additions and 78 deletions
|
|
@ -8,8 +8,7 @@ def setup(bot: bot.Bot):
|
||||||
@bot.slash_command(name="setfm", description="Sets your Last.fm username.")
|
@bot.slash_command(name="setfm", description="Sets your Last.fm username.")
|
||||||
async def setfm(ctx: nerimity.Context, username: str = None):
|
async def setfm(ctx: nerimity.Context, username: str = None):
|
||||||
if not username:
|
if not username:
|
||||||
await ctx.send(u.error_msg("Please provide your Last.fm username.\n\
|
await ctx.send(u.error_msg("Please provide your Last.fm username."))
|
||||||
usage: `/fm <your last.fm username>`"))
|
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
await bot.set_lastfm(ctx.author.id, username)
|
await bot.set_lastfm(ctx.author.id, username)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
import requests
|
|
||||||
|
|
||||||
import nerimity
|
import nerimity
|
||||||
import pylast
|
import pylast
|
||||||
|
|
||||||
|
|
@ -49,58 +47,3 @@ 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)
|
|
||||||
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,22 +1,3 @@
|
||||||
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}"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue