X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Flastfm.rb;h=ee9ef5bab92c92bf8a6ce050900ba312621496d4;hb=2fac249c8427e262a0a6654b1fc54a78ec1f8917;hp=dca347036f493a15b40b3255797d546ae5e9bd05;hpb=be6d4c5c331bec69d442368bfb91e31a9fa9cdb5;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/lastfm.rb b/data/rbot/plugins/lastfm.rb index dca34703..ee9ef5ba 100644 --- a/data/rbot/plugins/lastfm.rb +++ b/data/rbot/plugins/lastfm.rb @@ -269,18 +269,20 @@ class LastFmPlugin < Plugin rating = _("Very Low") end - reply = _("%{a}'s and %{b}'s musical compatibility rating is %{bold}%{r}%{bold}") % { + common_artists = unless artists.empty? + _(" and music they have in common includes: %{artists}") % { + :artists => Utils.comma_list(artists) } + else + nil + end + + m.reply _("%{a}'s and %{b}'s musical compatibility rating is %{bold}%{r}%{bold}%{common}") % { :a => user1, :b => user2, :r => rating.downcase, - :bold => Bold + :bold => Bold, + :common => common_artists } - - reply << _(" and music they have in common includes: %{artists}") % { - :artists => artists.join(", ") - } unless artists.empty? - - m.reply reply end def now_playing(m, params) @@ -416,6 +418,44 @@ class LastFmPlugin < Plugin end end + def find_venue(m, params) + venue = params[:venue].to_s + venues = search_venue_by(:name => venue, :limit => 1) + venue = venues.last + + if venues.empty? + m.reply "sorry, can't find such venue" + return + end + + reply = _("%{b}%{name}%{b}, %{street}, %{u}%{city}%{u}, %{country}, see %{url} for more info") % { + :u => Underline, :b => Bold, :name => venue.name, :city => venue.city, :street => venue.street, + :country => venue.country, :url => venue.url + } + + if venue.street && venue.city + maps_uri = "http://maps.google.com/maps?q=#{venue.street},+#{venue.city}" + maps_uri << ",+#{venue.postal}" if venue.postal + elsif venue.lat && venue.long + maps_uri = "http://maps.google.com/maps?q=#{venue.lat},+#{venue.long}" + else + m.reply reply + return + end + + maps_uri << "+(#{venue.name.gsub(" ", "%A0")})" + + begin + require "shorturl" + maps_uri = ShortURL.shorten(CGI.escape(maps_uri)) + rescue LoadError => e + error e + end + + reply << _(" and %{maps} for maps") % { :maps => maps_uri, :b => Bold } + m.reply reply + end + def get_album(artist, album) xml = @bot.httputil.get("#{APIURL}method=album.getinfo&artist=#{CGI.escape artist}&album=#{CGI.escape album}") unless xml @@ -545,14 +585,14 @@ class LastFmPlugin < Plugin elsif friends.length <= num reply = _("%{user} has %{total} friends: %{friends}") else - reply = _("%{user} has %{total} friends, including %{friends}") - reply << seemore + reply = _("%{user} has %{total} friends, including %{friends}%{seemore}") end m.reply reply % { :user => user, :total => friends.size, - :friends => friends.shuffle[0, num].join(", "), - :uri => "http://www.last.fm/user/#{CGI.escape user}/friends" + :friends => Utils.comma_list(friends.shuffle[0, num]), + :uri => "http://www.last.fm/user/#{CGI.escape user}/friends", + :seemore => seemore } when :lovedtracks loved = doc.root.get_elements("lovedtracks/track").map do |track| @@ -565,14 +605,14 @@ class LastFmPlugin < Plugin elsif loved.length <= num reply = _("%{user} has loved %{total} tracks: %{tracks}") else - reply = _("%{user} has loved %{total} tracks, including %{tracks}") - reply << seemore + reply = _("%{user} has loved %{total} tracks, including %{tracks}%{seemore}") end m.reply reply % { :user => user, :total => loved.size, - :tracks => loved_prep.join(", "), - :uri => "http://www.last.fm/user/#{CGI.escape user}/library/loved" + :tracks => Utils.comma_list(loved_prep), + :uri => "http://www.last.fm/user/#{CGI.escape user}/library/loved", + :seemore => seemore } when :neighbours nbrs = doc.root.get_elements("neighbours/user").map do |u| @@ -584,13 +624,13 @@ class LastFmPlugin < Plugin elsif nbrs.length <= num reply = _("%{user}'s musical neighbours are %{nbrs}") else - reply = _("%{user}'s musical neighbours include %{nbrs}") - reply << seemore + reply = _("%{user}'s musical neighbours include %{nbrs}%{seemore}") end m.reply reply % { - :user => user, - :nbrs => nbrs.shuffle[0, num].join(", "), - :uri => "http://www.last.fm/user/#{CGI.escape user}/neighbours" + :user => user, + :nbrs => Utils.comma_list(nbrs.shuffle[0, num]), + :uri => "http://www.last.fm/user/#{CGI.escape user}/neighbours", + :seemore => seemore } when :recenttracks tracks = doc.root.get_elements("recenttracks/track").map do |track| @@ -619,7 +659,7 @@ class LastFmPlugin < Plugin m.reply _("%{user} hasn't played anything recently") % { :user => user } else m.reply _("%{user} has recently played %{tracks}") % - { :user => user, :tracks => tracks_prep.join(", ") } + { :user => user, :tracks => Utils.comma_list(tracks_prep) } end when :shouts shouts = doc.root.get_elements("shouts/shout") @@ -677,6 +717,7 @@ plugin.map 'lastfm [:num] event[s] [for] *who', :action => :find_events, :requir 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 venue *venue', :action => :find_venue, :thread => true plugin.map 'lastfm set user[name] :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