From faf5648f579510bbeee638879c626fab92e3b6ea Mon Sep 17 00:00:00 2001 From: yuki Date: Wed, 8 Oct 2025 17:32:56 -0300 Subject: [PATCH] minor formatting --- bot.py | 6 +++--- commands/collage.py | 22 ++++++++++++---------- commands/config.py | 3 +-- commands/now_playing.py | 11 ++++------- commands/ping.py | 4 +++- main.py | 9 ++++----- 6 files changed, 27 insertions(+), 28 deletions(-) diff --git a/bot.py b/bot.py index cbc1770..105a27e 100644 --- a/bot.py +++ b/bot.py @@ -21,14 +21,14 @@ class Bot(nerimity.Client): # initialize last.fm client self.lastfm = pylast.LastFMNetwork( - api_key = lastfm_api_key, + api_key = lastfm_api_key, api_secret = lastfm_api_secret ) # initialize collage generator self.collage_generator = CollageGenerator( - lastfm_api_key=lastfm_api_key, - lastfm_api_secret=lastfm_api_secret + lastfm_api_key = lastfm_api_key, + lastfm_api_secret = lastfm_api_secret ) # initialize catbox client diff --git a/commands/collage.py b/commands/collage.py index 4a1d320..777a107 100644 --- a/commands/collage.py +++ b/commands/collage.py @@ -47,10 +47,11 @@ def setup(bot: bot.Bot): match timeframe: case "a" | "all" | "alltime" | "o": 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 "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": @@ -61,11 +62,11 @@ def setup(bot: bot.Bot): temp_msg = await ctx.send(f"Generating album chart for **{username}**...") image = bot.collage_generator.generate( - entity = "album", + entity = "album", username = username, - rows = int(size.split(sep="x")[0]), - cols = int(size.split(sep="x")[1]), - period = timeframe + rows = int(size.split(sep="x")[0]), + cols = int(size.split(sep="x")[1]), + period = timeframe ) img_bytes = io.BytesIO() @@ -86,9 +87,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}** {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"I crashed and burned while generating the chart:\n`{e}`")) + + finally: + if temp_msg: temp_msg.delete() diff --git a/commands/config.py b/commands/config.py index 1467019..a2a5577 100644 --- a/commands/config.py +++ b/commands/config.py @@ -8,8 +8,7 @@ def setup(bot: bot.Bot): @bot.slash_command(name="setfm", description="Sets your Last.fm username.") async def setfm(ctx: nerimity.Context, username: str = None): if not username: - await ctx.send(u.error_msg("Please provide your Last.fm username.\n\ - usage: `/fm `")) + await ctx.send(u.error_msg("Please provide your Last.fm username.\nusage: `/fm `")) return try: diff --git a/commands/now_playing.py b/commands/now_playing.py index c7c458a..b09301d 100644 --- a/commands/now_playing.py +++ b/commands/now_playing.py @@ -11,13 +11,11 @@ def setup(bot: bot.Bot): if lookup: username = lookup else: try: username = await bot.get_lastfm(ctx.author.id) - except Exception as e: - print(e) + except Exception as 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: @@ -35,10 +33,9 @@ def setup(bot: bot.Bot): track_artist = track.get_artist().get_name() track_artist_url = track.get_artist().get_url() - if now_playing == True: - await ctx.send(f"Now playing for **{username}**: [{track_name}]({track_url}) by [{track_artist}]({track_artist_url})") - else: - await ctx.send(f"Last played for **{username}**: [{track_name}]({track_url}) by [{track_artist}]({track_artist_url})") + np = "Now playing for" if now_playing else "Last played by" + + await ctx.send(f"{np} **{username}**: [{track_name}]({track_url}) by [{track_artist}]({track_artist_url})") except IndexError: await ctx.send(u.error_msg(f"User **{username}** has no recent tracks or they're set to private.")) diff --git a/commands/ping.py b/commands/ping.py index d9b581e..60e7d61 100644 --- a/commands/ping.py +++ b/commands/ping.py @@ -1,6 +1,8 @@ import nerimity -def setup(bot): +import bot + +def setup(bot: bot.Bot): @bot.command(name="ping") @bot.slash_command(name="ping", description="Ping...") async def ping(ctx: nerimity.Context): diff --git a/main.py b/main.py index 1bfd09b..d92d8b5 100644 --- a/main.py +++ b/main.py @@ -5,12 +5,11 @@ import bot with open("config.toml", "rb") as f: config = tomllib.load(f) -# nerimity client bot = bot.Bot( - prefix = '!', - token = config['token'], - owner_id = config['owner_id'], - lastfm_api_key = config['api_key'], + prefix = '!', + token = config['token'], + owner_id = config['owner_id'], + lastfm_api_key = config['api_key'], lastfm_api_secret = config['api_secret'] )