]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/lastfm.rb
grouphug: refactor confession retrieval
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / lastfm.rb
index 0c40701c6d98cfe34eb9d38c6967cf3263476533..67f8d5f78852d7eebb2ee3b8999baaabb0514d78 100644 (file)
@@ -82,7 +82,7 @@ class LastFmPlugin < Plugin
     when :now, :np
       _("lastfm now [<user>] => show the now playing track from last.fm.  np [<user>] does the same.")
     when :set
-      _("lastfm set nick <user> => associate your current irc nick with a last.fm user. lastfm set verb <present> <past> => set your preferred now playing verb. default \"listening\" and \"listened\".")
+      _("lastfm set user <user> => associate your current irc nick with a last.fm user. lastfm set verb <present> <past> => set your preferred now playing verb. default \"listening\" and \"listened\".")
     when :who
       _("lastfm who [<nick>] => show who <nick> is at last.fm. if <nick> is empty, show who you are at lastfm.")
     when :compare
@@ -146,7 +146,7 @@ class LastFmPlugin < Plugin
     }
     m.reply disp_events.join(' | '), :split_at => /\s+\|\s+/
 
-  end  
+  end
 
   def tasteometer(m, params)
     opts = { :cache => false }
@@ -159,7 +159,7 @@ class LastFmPlugin < Plugin
       return
     end
     if xml.class == Net::HTTPInternalServerError
-      if doc.root.elements["error"].attributes["code"] == "7" then 
+      if doc.root.elements["error"].attributes["code"] == "7" then
         error = doc.root.elements["error"].text
         error.match(/Invalid username: \[(.*)\]/);
         if @registry.has_key? $1 and not params[:recurs]
@@ -216,7 +216,7 @@ class LastFmPlugin < Plugin
       return
     end
     if xml.class == Net::HTTPBadRequest
-      if doc.root.elements["error"].text == "Invalid user name supplied" then 
+      if doc.root.elements["error"].text == "Invalid user name supplied" then
         if @registry.has_key? user and not params[:recurs]
           params[:who] = @registry[ user ]
           params[:recurs] = true
@@ -245,8 +245,12 @@ class LastFmPlugin < Plugin
       year = get_album(artist, albumtxt)[2]
       album = "[#{albumtxt}, #{year}] " if year
     end
-    date = first.elements["date"].attributes["uts"]
-    past = Time.at(date.to_i)
+    past = nil
+    date = XPath.first(first, "//date")
+    if date != nil
+      time = date.attributes["uts"]
+      past = Time.at(time.to_i)
+    end
     if now == "true"
        verb = _("listening")
        if @registry.has_key? "#{m.sourcenick}_verb_present"
@@ -276,7 +280,7 @@ class LastFmPlugin < Plugin
     end
     first = doc.root.elements["artist"]
     artist = first.elements["name"].text
-    playcount = first.elements["stats"].elements["plays"].text
+    playcount = first.elements["stats"].elements["playcount"].text
     listeners = first.elements["stats"].elements["listeners"].text
     summary = first.elements["bio"].elements["summary"].text
     m.reply _("%{b}%{a}%{b} has been played %{c} times and is being listened to by %{l} people.") % {:b => Bold, :a => artist, :c => playcount, :l => listeners}
@@ -334,7 +338,7 @@ class LastFmPlugin < Plugin
     playcount = first.elements["playcount"].text
     album = first.elements["name"].text
     date = first.elements["releasedate"].text
-    unless date.strip.length < 2 
+    unless date.strip.length < 2
       year = date.strip.split[2].chop
     end
     result = [artist, album, year, playcount]
@@ -371,7 +375,7 @@ class LastFmPlugin < Plugin
     nick = ""
     if params[:who]
       nick = params[:who].to_s
-    else 
+    else
       nick = m.sourcenick
     end
     if @registry.has_key? nick
@@ -422,6 +426,8 @@ plugin.map 'lastfm artist *artist', :action => :find_artist, :thread => true
 plugin.map 'lastfm album *album [by *artist]', :action => :find_album
 plugin.map 'lastfm track *track', :action => :find_track, :thread => true
 plugin.map 'lastfm set nick :who', :action => :set_user, :thread => true
+plugin.map 'lastfm set user :who', :action => :set_user, :thread => true
+plugin.map 'lastfm set username :who', :action => :set_user, :thread => true
 plugin.map 'lastfm set verb :present :past', :action => :set_verb, :thread => true
 plugin.map 'lastfm who :who', :action => :get_user, :thread => true
 plugin.map 'lastfm who', :action => :get_user, :thread => true