add album charts
This commit is contained in:
parent
bd54c8c9cd
commit
425f921be7
2 changed files with 69 additions and 1 deletions
6
bot.py
6
bot.py
|
|
@ -5,6 +5,8 @@ import nerimity
|
|||
import pylast
|
||||
import aiosqlite
|
||||
|
||||
from pyzxz.pyzxz.pyzxz import ZeroXZero # :sob:
|
||||
|
||||
from lastfmcollagegenerator.collage_generator import CollageGenerator
|
||||
# from catbox_async_uploader.catbox_async_uploader.core import CatboxAsyncUploader
|
||||
|
||||
|
|
@ -32,11 +34,13 @@ class Bot(nerimity.Client):
|
|||
# initialize catbox client
|
||||
# self.catbox_uploader = CatboxAsyncUploader(userhash=catbox_hash)
|
||||
|
||||
# initialize 0x0 client
|
||||
self.zxz = ZeroXZero("https://x0.at")
|
||||
|
||||
# database
|
||||
self.db = None
|
||||
self.db_file = db_file
|
||||
|
||||
|
||||
def load_commands(self, commands_dir: str):
|
||||
for filename in os.listdir(commands_dir):
|
||||
if filename.endswith(".py") and not filename.startswith("_"):
|
||||
|
|
|
|||
64
commands/collage.py
Normal file
64
commands/collage.py
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
import io
|
||||
|
||||
import nerimity
|
||||
|
||||
import bot
|
||||
import utils as u
|
||||
|
||||
# from catbox_async_uploader.catbox_async_uploader.enums import LitterboxDuration
|
||||
# from pyzxz import ZeroXZero
|
||||
|
||||
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):
|
||||
if 'x' not in size:
|
||||
await ctx.send(u.error_msg("Please provide a valid size.\nie `/chart album 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
|
||||
|
||||
try:
|
||||
temp_msg = await ctx.send(f"Generating album chart for **{username}**...")
|
||||
|
||||
image = bot.collage_generator.generate(
|
||||
entity = "album",
|
||||
username = username,
|
||||
rows = int(size.split(sep="x")[0]),
|
||||
cols = int(size.split(sep="x")[1]),
|
||||
period = timeframe
|
||||
)
|
||||
|
||||
img_bytes = io.BytesIO()
|
||||
image.save(fp=img_bytes, format="png")
|
||||
|
||||
# link = await bot.catbox_uploader.upload_to_litterbox(
|
||||
# file_path_or_bytes = img_bytes,
|
||||
# file_name = "collage.png",
|
||||
# duration = LitterboxDuration.H12
|
||||
# )
|
||||
|
||||
# attachment = await u.construct_attachment_from_bytes(
|
||||
# filename = "chart",
|
||||
# file_type = "png",
|
||||
# bytes_arr = img_bytes,
|
||||
# ).upload()
|
||||
|
||||
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}"))
|
||||
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}`"))
|
||||
Loading…
Add table
Reference in a new issue