Compare commits

..

No commits in common. "6c919081c73c94f7dc49273c7bd6b83cbda92ba7" and "c959404452f0a4c3c3a4140560f5fb12c99bf3ba" have entirely different histories.

3 changed files with 64 additions and 105 deletions

View file

@ -1,8 +0,0 @@
import nerimity
import bot
def setup(bot: bot.Bot):
@bot.command(name="topartists", aliases=["ta","topartist"])
@bot.slash_command(name="topartists")
def topartists(ctx: nerimity.Context, timeframe)

View file

@ -8,123 +8,89 @@ import utils as u
# from catbox_async_uploader.catbox_async_uploader.enums import LitterboxDuration # from catbox_async_uploader.catbox_async_uploader.enums import LitterboxDuration
# from pyzxz import ZeroXZero # from pyzxz import ZeroXZero
async def send_collage(bot: bot.Bot, ctx: nerimity.Context, entity: str, size: str = "3x3", timeframe: str = "7day", username: str = None): def setup(bot: bot.Bot):
temp_msg = None @bot.command(name="chart", aliases=["c", "chartalbum", "albumchart", "collage"])
@bot.slash_command(name="chartalbum", description="Generate an album collage.")
async def chartalbum(ctx: nerimity.Context, size: str = "3x3", timeframe: str = "7day", username: str = None):
temp_msg = None
if 'x' not in size: if 'x' not in size:
await ctx.send(u.error_msg(f"Please provide a valid size.\nie `/chart{entity} 5x5`")) await ctx.send(u.error_msg("Please provide a valid size.\nie `/chartalbum 5x5`"))
return
if int(size.split('x')[0]) > 5 or int(size.split('x')[1]) > 5:
await ctx.send(u.error_msg("Maximum size allowed is 5x5."))
return
if not username:
try: username = await bot.get_lastfm(ctx.author.id)
except Exception as e:
print(e)
await ctx.send(u.error_msg(f"Unknown database error:\n{e}"))
if not username:
await ctx.send(u.error_msg("Please provide a Last.fm username (or set yours with `/setfm`)."))
print("returned")
return return
if username.startswith("[@:"): if int(size.split('x')[0]) > 5 or int(size.split('x')[1]) > 5:
mentioned = bot.get_user(username[3:-1]) await ctx.send(u.error_msg("Maximum size allowed is 5x5."))
try: username = await bot.get_lastfm(mentioned.id) return
if not username:
try: username = await bot.get_lastfm(ctx.author.id)
except Exception as e: except Exception as e:
print(e) print(e)
await ctx.send(u.error_msg(f"Unknown database error:\n{e}")) await ctx.send(u.error_msg(f"Unknown database error:\n{e}"))
if not username: if not username:
await ctx.send(u.error_msg(f"[@:{mentioned.id}] doesn't seem to have an account set. Do so with `/setfm`.")) await ctx.send(u.error_msg("Please provide a Last.fm username (or set yours with `/setfm`)."))
print("returned") print("returned")
return return
match timeframe: if username.startswith("[@:"):
case "a" | "all" | "alltime" | "o": timeframe = "overall" mentioned = bot.get_user(username[3:-1])
case "y" | "year" | "yearly": timeframe = "12month" try: username = await bot.get_lastfm(mentioned.id)
case "m" | "month" | "monthly": timeframe = "1month" except Exception as e:
case "w" | "week" | "weekly": timeframe = "7day" print(e)
case "d" | "day" | "daily": timeframe = "1day" await ctx.send(u.error_msg(f"Unknown database error:\n{e}"))
case _: "7day" if not username:
await ctx.send(u.error_msg(f"[@:{mentioned.id}] doesn't seem to have an account set. Do so with `/setfm`."))
print("returned")
return
if timeframe == "1day": match timeframe:
await ctx.send(u.error_msg("Daily charts are not yet supported. Sorry!!")) case "a" | "all" | "alltime" | "o": timeframe = "overall"
return case "y" | "year" | "yearly": timeframe = "12month"
case "m" | "month" | "monthly": timeframe = "1month"
case "w" | "week" | "weekly": timeframe = "7day"
case "d" | "day" | "daily": timeframe = "1day"
try: case _: "7day"
temp_msg = await ctx.send(f"Generating {entity} chart for **{username}**...")
image = bot.collage_generator.generate( if timeframe == "1day":
entity = entity, await ctx.send(u.error_msg("Daily charts are not yet supported. Sorry!!"))
username = username, return
rows = int(size.split(sep="x")[0]),
cols = int(size.split(sep="x")[1]),
period = timeframe
)
img_bytes = io.BytesIO() try:
image.save(fp=img_bytes, format="png") temp_msg = await ctx.send(f"Generating album chart for **{username}**...")
# link = await bot.catbox_uploader.upload_to_litterbox( image = bot.collage_generator.generate(
# file_path_or_bytes = img_bytes, entity = "album",
# file_name = "collage.png", username = username,
# duration = LitterboxDuration.H12 rows = int(size.split(sep="x")[0]),
# ) cols = int(size.split(sep="x")[1]),
period = timeframe
)
# attachment = await u.construct_attachment_from_bytes( img_bytes = io.BytesIO()
# filename = "chart", image.save(fp=img_bytes, format="png")
# file_type = "png",
# bytes_arr = img_bytes,
# ).upload()
link = await bot.zxz.upload_from_bytes(img_bytes.getvalue(), f"{entity}_chart.png") # link = await bot.catbox_uploader.upload_to_litterbox(
# file_path_or_bytes = img_bytes,
# file_name = "collage.png",
# duration = LitterboxDuration.H12
# )
await ctx.send(u.good_msg(f"**{size}** {timeframe} {entity} chart for [{username}](https://last.fm/user/{username}) successfully generated:\n{link}")) # attachment = await u.construct_attachment_from_bytes(
# filename = "chart",
# file_type = "png",
# bytes_arr = img_bytes,
# ).upload()
except Exception as e: link = await bot.zxz.upload_from_bytes(img_bytes.getvalue(), "chart.png")
print(e)
await ctx.send(u.error_msg(f"I crashed and burned while generating the chart:\n`{e}`"))
finally: await ctx.send(u.good_msg(f"**{size}** {timeframe} chart for [{username}](https://last.fm/user/{username}) successfully generated:\n{link}"))
if temp_msg: temp_msg.delete()
def setup(bot: bot.Bot): except Exception as e:
@bot.command(name="chart", aliases=["c", "chartalbum", "albumchart", "collage"]) print(e)
@bot.slash_command(name="chartalbum", description="Generate an album collage.") await ctx.send(u.error_msg(f"I crashed and burned while generating the chart:\n`{e}`"))
async def chartalbum(ctx: nerimity.Context, size: str = "3x3", timeframe: str = "7day", username: str = None):
await send_collage(
bot = bot,
ctx = ctx,
entity = "album",
size = size,
timeframe = timeframe,
username = username
)
@bot.command(name="artistchart", aliases=["ac", "ca", "chartartist", "artistcollage"]) finally:
@bot.slash_command(name="chartartist", description="Generate an artist collage.") if temp_msg: temp_msg.delete()
async def chartartist(ctx: nerimity.Context, size: str = "3x3", timeframe: str = "7day", username: str = None):
await send_collage(
bot = bot,
ctx = ctx,
entity = "artist",
size = size,
timeframe = timeframe,
username = username
)
@bot.command(name="trackchart", aliases=["tc", "ct", "charttrack", "chartracks", "songchart", "chartsong", "trackcollage", "songcollage"])
@bot.slash_command(name="charttrack", description="Generate a track/song collage.")
async def charttrack(ctx: nerimity.Context, size: str = "3x3", timeframe: str = "7day", username: str = None):
await send_collage(
bot = bot,
ctx = ctx,
entity = "track",
size = size,
timeframe = timeframe,
username = username
)

View file

@ -86,7 +86,8 @@ def setup(bot: bot.Bot):
cover_art = albumobj.get_cover_image() 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.")) 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()})**:\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)