From 980c4153acb9ed4d421938d06318b037d12ca508 Mon Sep 17 00:00:00 2001 From: yuki Date: Tue, 7 Oct 2025 01:51:05 -0300 Subject: [PATCH] migrate np command to folder --- commands/now_playing.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 commands/now_playing.py diff --git a/commands/now_playing.py b/commands/now_playing.py new file mode 100644 index 0000000..282f15b --- /dev/null +++ b/commands/now_playing.py @@ -0,0 +1,38 @@ +import nerimity +import pylast + +import commands.utils as u + +def setup(bot): + @bot.command(name="fm", aliases=["np"]) + @bot.slash_command(name="fm", description="Shows what you're currently playing") + async def fm(ctx: nerimity.Context, params: str = ""): + username = params if params else "kaaisudev" + + try: + track = bot.lastfm.get_user(username).get_now_playing() + if track == None: + now_playing = False + played_track = bot.lastfm.get_user(username).get_recent_tracks(limit=1) + track = played_track[0].track + + else: + now_playing = True + + track_url = track.get_url() + track_name = track.get_name() + 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})") + + except IndexError: + await ctx.send(u.error_msg("User has no recent tracks or they're set to private.")) + except pylast.WSError: + await ctx.send(u.error_msg("User not found.")) + except Exception as e: + print(e) + await ctx.send(u.error_msg("Unknown error."))