migrate np command to folder
This commit is contained in:
parent
1aebafc648
commit
980c4153ac
1 changed files with 38 additions and 0 deletions
38
commands/now_playing.py
Normal file
38
commands/now_playing.py
Normal file
|
|
@ -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."))
|
||||
Loading…
Add table
Reference in a new issue