]> 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 811a63aa1dc5e6057948aa007082dde4b65d0d94..7438583d04b7e8b8d76e55b8a8c3a8e9267977fc 100644 (file)
@@ -469,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
@@ -620,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(?:tracks)?|recent(?:t?racks)?|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