correctly handle resolving and whitesace

master
Casey Link 2011-02-05 14:12:47 -05:00
parent df48e246a7
commit 93c39b3f28
1 changed files with 11 additions and 5 deletions

View File

@ -70,11 +70,17 @@ lastfm_set.rule = (['lastfm-set'], r'(\S+)\s+(?:(.*?),(.*)|(\S+))')
def now_playing(phenny, input): def now_playing(phenny, input):
nick = input.nick nick = input.nick
user = input.group(2) user = ""
if not user or len(user.strip()) == 0: arg = input.group(2)
user = resolve_username(nick) if not arg or len(arg.strip()) == 0:
if not user: user = resolve_username(nick) # use the sender
if not user: #nick didnt resolve
user = nick user = nick
else: # use the argument
user = resolve_username(arg.strip())
if not user: # user didnt resolve
user = arg
user = user.strip()
try: try:
req = urlopen("%smethod=user.getrecenttracks&user=%s" % (APIURL, urlquote(user))) req = urlopen("%smethod=user.getrecenttracks&user=%s" % (APIURL, urlquote(user)))
except HTTPError, e: except HTTPError, e: