]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/lastfm.rb
markov: add command for learning from files
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / lastfm.rb
index 8742e4f72e785cc02d1a55f5ef4a46c04e29e73d..7438583d04b7e8b8d76e55b8a8c3a8e9267977fc 100644 (file)
@@ -441,8 +441,9 @@ class LastFmPlugin < Plugin
 
   def lastfm(m, params)
     action = case params[:action]
-    when "neighbors"   then "neighbours"
-    when "recentracks" then "recenttracks"
+    when "neighbors" then "neighbours"
+    when "recentracks", "recent" then "recenttracks"
+    when "loved" then "lovedtracks"
     when /^weekly(track|album|artist)s$/
       "weekly#{$1}chart"
     when "events"
@@ -468,10 +469,12 @@ class LastFmPlugin < Plugin
       uri << "&period=#{period_uri}"
     end
 
-    res = @bot.httputil.get_response(uri)
-    unless res.body
-      m.reply _("I had problems accessing last.fm")
-      return
+    begin
+      res = @bot.httputil.get_response(uri)
+      raise _("no response body") unless res.body
+    rescue Exception => e
+        m.reply _("I had problems accessing last.fm: %{e}") % {:e => e.message}
+        return
     end
     doc = Document.new(res.body)
     unless doc
@@ -619,13 +622,15 @@ plugin.map 'lastfm who [:who]', :action => :get_user, :thread => true
 plugin.map 'lastfm compare to :user2', :action => :tasteometer, :thread => true
 plugin.map 'lastfm compare [:user1] [to] :user2', :action => :tasteometer, :thread => true
 plugin.map "lastfm [user] [:num] :action [:user]", :thread => true,
-  :requirements => { :action =>
-    /^(?:events|shouts|friends|neighbou?rs|(?:loved|recent?)tracks|top(?:album|artist|track)s?|weekly(?:albums?|artists?|tracks?)(?:chart)?)$/
+  :requirements => {
+    :action => /^(?:events|shouts|friends|neighbou?rs|loved(?:tracks)?|recent(?:t?racks)?|top(?:album|artist|track)s?|weekly(?:albums?|artists?|tracks?)(?:chart)?)$/,
+    :num => /^\d+$/
 }
 plugin.map 'lastfm [user] [:num] :action [:user] over [*period]', :thread => true,
   :requirements => {
     :action => /^(?:top(?:album|artist|track)s?)$/,
-    :period => /^(?:(?:3|6|12) months)|(?:a\s|1\s)?year$/
+    :period => /^(?:(?:3|6|12) months)|(?:a\s|1\s)?year$/,
+    :num => /^\d+$/
 }
 plugin.map 'lastfm [now] [:who]', :action => :now_playing, :thread => true
 plugin.map 'np [:who]', :action => :now_playing, :thread => true