X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Flastfm.rb;h=7438583d04b7e8b8d76e55b8a8c3a8e9267977fc;hb=eec8d96e5c8f0c44148cc97a40b75a57e399cf6e;hp=9801f9a1aabcf9c24ce400ebb2d69159a176be72;hpb=8e8385ee8aa0952d88fe2a02b9e1799aa5a9502a;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/lastfm.rb b/data/rbot/plugins/lastfm.rb index 9801f9a1..7438583d 100644 --- a/data/rbot/plugins/lastfm.rb +++ b/data/rbot/plugins/lastfm.rb @@ -6,10 +6,12 @@ # Author:: Jeremy Voorhis # Author:: Giuseppe "Oblomov" Bilotta # Author:: Casey Link +# Author:: Raine Virta # # Copyright:: (C) 2005 Jeremy Voorhis # Copyright:: (C) 2007 Giuseppe Bilotta # Copyright:: (C) 2008 Casey Link +# Copyright:: (C) 2009 Raine Virta # # License:: GPL v2 @@ -82,6 +84,7 @@ class LastFmPlugin < Plugin end def help(plugin, topic="") + period = _(", where can be one of: 3|6|12 months, a year") case (topic.intern rescue nil) when :event, :events _("lastfm [] events in => show information on events in or near . lastfm [] events by => show information on events by . The number of events that can be displayed is optional, defaults to %{d} and cannot be higher than %{m}") % {:d => @bot.config['lastfm.default_events'], :m => @bot.config['lastfm.max_events']} @@ -92,15 +95,37 @@ class LastFmPlugin < Plugin when :track _("lastfm track => search tracks matching on last.fm") when :now, :np - _("lastfm now [] => show the now playing track from last.fm. np [] does the same.") + _("lastfm now [] => show the now playing track from last.fm. np [] does the same.") when :set _("lastfm set user => associate your current irc nick with a last.fm user. lastfm set verb , => set your preferred now playing/just played verbs. default \"is listening to\" and \"listened to\".") when :who _("lastfm who [] => show who is on last.fm. if is empty, show who you are on lastfm.") when :compare _("lastfm compare [] => show musical taste compatibility between nick1 (or user if omitted) and nick2") + when :shouts + _("lastfm shouts [] => show shouts to ") + when :friends + _("lastfm friends [] => show 's friends") + when :neighbors, :neighbours + _("lastfm neighbors [] => show people who share similar musical taste as ") + when :lovedtracks + _("lastfm loved[tracks] [] => show tracks that has loved") + when :recenttracks, :recentracks + _("lastfm recent[tracks] [] => show tracks that has recently played") + when :topalbums + _("lastfm topalbums [] [over ] => show 's top albums%{p}") % { :p => period } + when :topartists + _("lastfm topartists [] [over ] => show 's top artists%{p}") % { :p => period } + when :toptracks + _("lastfm toptracks [] [over ] => show 's top tracks%{p}") % { :p => period } + when :weeklyalbumchart + _("lastfm weeklyalbumchart [] => show 's weekly album chart") + when :weeklyartistchart + _("lastfm weeklyartistchart [] => show 's weekly artist chart") + when :weeklytrackchart + _("lastfm weeklyartistchart [] => show 's weekly track chart") else - _("lastfm [] => show your or 's now playing track on lastfm. np [] => same as 'lastfm'. other topics: events, artist, album, track, now, set, who, compare") + _("last.fm plugin - topics: events, artist, album, track, now, set, who, compare, shouts, friends, neighbors, (loved|recent)tracks, top(albums|tracks|artists), weekly(album|artist|track)chart") end end @@ -416,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" @@ -443,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 @@ -556,7 +584,7 @@ class LastFmPlugin < Plugin format = "%{artist} (%{bold}%{plays}%{bold})" artist = item.elements["name"].text when :toptracks, :topalbums - format = "%{artist} - (%{title} %{bold}%{plays}%{bold})" + format = "%{artist} - %{title} (%{bold}%{plays}%{bold})" artist = item.elements["artist/name"].text end @@ -594,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