add setfm
This commit is contained in:
parent
6a9c1038d2
commit
4fa08e9e97
2 changed files with 56 additions and 27 deletions
18
commands/config.py
Normal file
18
commands/config.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import nerimity
|
||||
|
||||
import bot
|
||||
import utils as u
|
||||
|
||||
def setup(bot: bot.Bot):
|
||||
@bot.command(name="setfm", aliases=["setuser", "setlastfm"])
|
||||
@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."))
|
||||
else:
|
||||
try:
|
||||
await bot.set_lastfm(ctx.author.id, username)
|
||||
await ctx.send(u.good_msg(f"Your Last.fm user has been set to **{username}**!"))
|
||||
except Exception as e:
|
||||
print(e)
|
||||
await ctx.send(u.error_msg("Unknown database error."))
|
||||
|
|
@ -1,19 +1,29 @@
|
|||
import nerimity
|
||||
import pylast
|
||||
|
||||
import commands.utils as u
|
||||
import bot
|
||||
import utils as u
|
||||
|
||||
def setup(bot):
|
||||
def setup(bot: bot.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"
|
||||
async def fm(ctx: nerimity.Context, lookup: str = None):
|
||||
if lookup: username = lookup
|
||||
else:
|
||||
try: username = await bot.get_lastfm(ctx.author.id)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
await ctx.send(u.error_msg("Unknown database error."))
|
||||
|
||||
if not username:
|
||||
await ctx.send(u.error_msg("Please provide a Last.fm username (or set yours with `/setfm`)"))
|
||||
else:
|
||||
try:
|
||||
track = bot.lastfm.get_user(username).get_now_playing()
|
||||
user = bot.lastfm.get_user(username)
|
||||
track = user.get_now_playing()
|
||||
if track == None:
|
||||
now_playing = False
|
||||
played_track = bot.lastfm.get_user(username).get_recent_tracks(limit=1)
|
||||
played_track = user.get_recent_tracks(limit=1)
|
||||
track = played_track[0].track
|
||||
|
||||
else:
|
||||
|
|
@ -30,9 +40,10 @@ def setup(bot):
|
|||
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."))
|
||||
await ctx.send(u.error_msg(f"User **{username}** has no recent tracks or they're set to private."))
|
||||
except pylast.WSError:
|
||||
await ctx.send(u.error_msg("User not found."))
|
||||
await ctx.send(u.error_msg(f"User **{username}** not found."))
|
||||
|
||||
except Exception as e:
|
||||
print(e)
|
||||
await ctx.send(u.error_msg("Unknown error."))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue