Compare commits
7 commits
c959404452
...
6c919081c7
| Author | SHA1 | Date | |
|---|---|---|---|
| 6c919081c7 | |||
| 8b496f7b12 | |||
| 13852f59d3 | |||
| 48e6a4442a | |||
| 4ce5bdc805 | |||
| d130a1a3c5 | |||
| f9dc2e5b94 |
3 changed files with 105 additions and 64 deletions
8
commands/_top.py
Normal file
8
commands/_top.py
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
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)
|
||||||
|
|
@ -8,89 +8,123 @@ 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
|
||||||
|
|
||||||
def setup(bot: bot.Bot):
|
async def send_collage(bot: bot.Bot, ctx: nerimity.Context, entity: str, size: str = "3x3", timeframe: str = "7day", username: str = None):
|
||||||
@bot.command(name="chart", aliases=["c", "chartalbum", "albumchart", "collage"])
|
temp_msg = None
|
||||||
@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("Please provide a valid size.\nie `/chartalbum 5x5`"))
|
await ctx.send(u.error_msg(f"Please provide a valid size.\nie `/chart{entity} 5x5`"))
|
||||||
return
|
return
|
||||||
|
|
||||||
if int(size.split('x')[0]) > 5 or int(size.split('x')[1]) > 5:
|
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."))
|
await ctx.send(u.error_msg("Maximum size allowed is 5x5."))
|
||||||
return
|
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:
|
if not username:
|
||||||
try: username = await bot.get_lastfm(ctx.author.id)
|
await ctx.send(u.error_msg("Please provide a Last.fm username (or set yours with `/setfm`)."))
|
||||||
|
print("returned")
|
||||||
|
return
|
||||||
|
|
||||||
|
if username.startswith("[@:"):
|
||||||
|
mentioned = bot.get_user(username[3:-1])
|
||||||
|
try: username = await bot.get_lastfm(mentioned.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("Please provide a Last.fm username (or set yours with `/setfm`)."))
|
await ctx.send(u.error_msg(f"[@:{mentioned.id}] doesn't seem to have an account set. Do so with `/setfm`."))
|
||||||
print("returned")
|
print("returned")
|
||||||
return
|
return
|
||||||
|
|
||||||
if username.startswith("[@:"):
|
match timeframe:
|
||||||
mentioned = bot.get_user(username[3:-1])
|
case "a" | "all" | "alltime" | "o": timeframe = "overall"
|
||||||
try: username = await bot.get_lastfm(mentioned.id)
|
case "y" | "year" | "yearly": timeframe = "12month"
|
||||||
except Exception as e:
|
case "m" | "month" | "monthly": timeframe = "1month"
|
||||||
print(e)
|
case "w" | "week" | "weekly": timeframe = "7day"
|
||||||
await ctx.send(u.error_msg(f"Unknown database error:\n{e}"))
|
case "d" | "day" | "daily": timeframe = "1day"
|
||||||
|
|
||||||
if not username:
|
case _: "7day"
|
||||||
await ctx.send(u.error_msg(f"[@:{mentioned.id}] doesn't seem to have an account set. Do so with `/setfm`."))
|
|
||||||
print("returned")
|
|
||||||
return
|
|
||||||
|
|
||||||
match timeframe:
|
if timeframe == "1day":
|
||||||
case "a" | "all" | "alltime" | "o": timeframe = "overall"
|
await ctx.send(u.error_msg("Daily charts are not yet supported. Sorry!!"))
|
||||||
case "y" | "year" | "yearly": timeframe = "12month"
|
return
|
||||||
case "m" | "month" | "monthly": timeframe = "1month"
|
|
||||||
case "w" | "week" | "weekly": timeframe = "7day"
|
|
||||||
case "d" | "day" | "daily": timeframe = "1day"
|
|
||||||
|
|
||||||
case _: "7day"
|
try:
|
||||||
|
temp_msg = await ctx.send(f"Generating {entity} chart for **{username}**...")
|
||||||
|
|
||||||
if timeframe == "1day":
|
image = bot.collage_generator.generate(
|
||||||
await ctx.send(u.error_msg("Daily charts are not yet supported. Sorry!!"))
|
entity = entity,
|
||||||
return
|
username = username,
|
||||||
|
rows = int(size.split(sep="x")[0]),
|
||||||
|
cols = int(size.split(sep="x")[1]),
|
||||||
|
period = timeframe
|
||||||
|
)
|
||||||
|
|
||||||
try:
|
img_bytes = io.BytesIO()
|
||||||
temp_msg = await ctx.send(f"Generating album chart for **{username}**...")
|
image.save(fp=img_bytes, format="png")
|
||||||
|
|
||||||
image = bot.collage_generator.generate(
|
# link = await bot.catbox_uploader.upload_to_litterbox(
|
||||||
entity = "album",
|
# file_path_or_bytes = img_bytes,
|
||||||
username = username,
|
# file_name = "collage.png",
|
||||||
rows = int(size.split(sep="x")[0]),
|
# duration = LitterboxDuration.H12
|
||||||
cols = int(size.split(sep="x")[1]),
|
# )
|
||||||
period = timeframe
|
|
||||||
)
|
|
||||||
|
|
||||||
img_bytes = io.BytesIO()
|
# attachment = await u.construct_attachment_from_bytes(
|
||||||
image.save(fp=img_bytes, format="png")
|
# filename = "chart",
|
||||||
|
# file_type = "png",
|
||||||
|
# bytes_arr = img_bytes,
|
||||||
|
# ).upload()
|
||||||
|
|
||||||
# link = await bot.catbox_uploader.upload_to_litterbox(
|
link = await bot.zxz.upload_from_bytes(img_bytes.getvalue(), f"{entity}_chart.png")
|
||||||
# file_path_or_bytes = img_bytes,
|
|
||||||
# file_name = "collage.png",
|
|
||||||
# duration = LitterboxDuration.H12
|
|
||||||
# )
|
|
||||||
|
|
||||||
# attachment = await u.construct_attachment_from_bytes(
|
await ctx.send(u.good_msg(f"**{size}** {timeframe} {entity} chart for [{username}](https://last.fm/user/{username}) successfully generated:\n{link}"))
|
||||||
# filename = "chart",
|
|
||||||
# file_type = "png",
|
|
||||||
# bytes_arr = img_bytes,
|
|
||||||
# ).upload()
|
|
||||||
|
|
||||||
link = await bot.zxz.upload_from_bytes(img_bytes.getvalue(), "chart.png")
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
await ctx.send(u.error_msg(f"I crashed and burned while generating the chart:\n`{e}`"))
|
||||||
|
|
||||||
await ctx.send(u.good_msg(f"**{size}** {timeframe} chart for [{username}](https://last.fm/user/{username}) successfully generated:\n{link}"))
|
finally:
|
||||||
|
if temp_msg: temp_msg.delete()
|
||||||
|
|
||||||
except Exception as e:
|
def setup(bot: bot.Bot):
|
||||||
print(e)
|
@bot.command(name="chart", aliases=["c", "chartalbum", "albumchart", "collage"])
|
||||||
await ctx.send(u.error_msg(f"I crashed and burned while generating the chart:\n`{e}`"))
|
@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):
|
||||||
|
await send_collage(
|
||||||
|
bot = bot,
|
||||||
|
ctx = ctx,
|
||||||
|
entity = "album",
|
||||||
|
size = size,
|
||||||
|
timeframe = timeframe,
|
||||||
|
username = username
|
||||||
|
)
|
||||||
|
|
||||||
finally:
|
@bot.command(name="artistchart", aliases=["ac", "ca", "chartartist", "artistcollage"])
|
||||||
if temp_msg: temp_msg.delete()
|
@bot.slash_command(name="chartartist", description="Generate an artist collage.")
|
||||||
|
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
|
||||||
|
)
|
||||||
|
|
|
||||||
|
|
@ -86,8 +86,7 @@ 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()})**:\
|
else: await ctx.send(f"Here's the cover art for **[{albumobj.get_name()}]({albumobj.get_url()})**:\n{cover_art}")
|
||||||
{cover_art}")
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue