Error when user doesnt exist and some minor fixes.

This commit is contained in:
Pedro de Oliveira 2020-02-06 21:32:23 +00:00
parent d04f84cb4b
commit d65870d5db
1 changed files with 16 additions and 10 deletions

View File

@ -136,13 +136,16 @@ class LastFM(callbacks.Plugin):
return True
def setuser(self, irc, msg, args, channel, user):
"""[<channel>] <last.fm user>
"""[<channel>] <last.fm account>
Assigns the <last.fm account> to the current nick, in [channel].
"""
userinfo = self.network.get_user(user)
if not userinfo:
irc.error("User not found", prefixNick=False)
try:
userinfo.get_registered()
except pylast.WSError as e:
irc.error(str(e), prefixNick=False)
return
self.db.set_user(channel, msg.nick.lower(), user)
@ -156,7 +159,7 @@ class LastFM(callbacks.Plugin):
def compare(self, irc, msg, args, channel, user):
"""[<channel>] <last.fm account/nick>
Compares your account with the <last.fm account/nick> account, in [channel].
Compares your account with the <last.fm account/nick>, in [channel].
"""
if self.connect() is False:
return
@ -213,9 +216,9 @@ class LastFM(callbacks.Plugin):
compare = wrap(compare, ['channel', 'anything'])
def nowplaying(self, irc, msg, args, channel, user):
"""[<channel>] [<last.fm user>]
"""[<channel>] [<last.fm account/nick>]
Show the currently playing song, by [last.fm user], in [channel].
Show the currently playing song, by [last.fm account/nick], in [channel].
"""
if self.connect() is False:
return
@ -226,8 +229,11 @@ class LastFM(callbacks.Plugin):
username = self.db.get_user(channel, msg.nick.lower())
userinfo = self.network.get_user(username)
if not userinfo:
irc.error("User not found", prefixNick=False)
try:
userinfo.get_registered()
except pylast.WSError as e:
irc.error(str(e), prefixNick=False)
return
track = userinfo.get_now_playing()
@ -248,7 +254,7 @@ class LastFM(callbacks.Plugin):
message = "{} {} is not playing anything right now".format(
self.prepend,
msg.nick
username
)
if track:
@ -272,7 +278,7 @@ class LastFM(callbacks.Plugin):
message = "{} {} is listening to: {} {}({} plays) {}".format(
self.prepend,
msg.nick,
username,
track,
lovemsg,
playcount,