finish album collage generation

This commit is contained in:
yuki 2025-10-08 06:27:53 -03:00
parent 7b97cdca3d
commit 615f0cd184
2 changed files with 22 additions and 4 deletions

View file

@ -10,7 +10,7 @@ dead simple last.fm bot
**TODO:**
- add database username checker to utils.py
- add collage generation ✅ (partial)
- ~~add collage generation~~
- fix attachment generation and upload
- ~~**temporary fix**: upload and link to catbox urls~~ __the asynchronous catbox library does not accept byte arrays__
- ~~**temporary fix**: construct the attachment object from scratch and upload manually(?)~~ __its still broken__

View file

@ -11,10 +11,16 @@ import utils as u
def setup(bot: bot.Bot):
@bot.command(name="chart", aliases=["c", "chartalbum", "albumchart", "collage"])
@bot.slash_command(name="chartalbum", description="Generate an album collage.")
async def chart_album(ctx: nerimity.Context, size: str = "5x5", timeframe: str = "7day", username: str = None):
async def chart_album(ctx: nerimity.Context, size: str = "3x3", timeframe: str = "7day", username: str = None):
temp_msg = None
if 'x' not in size:
await ctx.send(u.error_msg("Please provide a valid size.\nie `/chart album 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)
@ -27,6 +33,18 @@ def setup(bot: bot.Bot):
print("returned")
return
match timeframe:
case "a" | "all" | "alltime" | "o" | "overall": timeframe = "overall"
case "y" | "year" | "yearly": timeframe = "12month"
case "m" | "month" | "monthly": timeframe = "1month"
case "w" | "week" | "weekly": timeframe = "7day"
case "d" | "day" | "daily": timeframe = "1day"
case _: "7day"
if timeframe == "1day":
ctx.send(u.error_msg("Daily charts are not yet supported. Sorry!!"))
return
try:
temp_msg = await ctx.send(f"Generating album chart for **{username}**...")
@ -55,10 +73,10 @@ def setup(bot: bot.Bot):
link = await bot.zxz.upload_from_bytes(img_bytes.getvalue(), "chart.png")
await ctx.send(u.good_msg(f"{size} Chart for {username} successfully generated:\n{link}"))
await ctx.send(u.good_msg(f"**{size}** {timeframe} chart for [{username}](https://last.fm/user/{username}) successfully generated:\n{link}"))
temp_msg.delete()
except Exception as e:
if temp_msg: temp_msg.delete()
print(e)
await ctx.send(u.error_msg(f"Unknown error:\n`{e}`"))
await ctx.send(u.error_msg(f"I crashed and burned while generating the chart:\n`{e}`"))