]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/lastfm.rb
reaction: spoken reactions should use plainreply, not reply
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / lastfm.rb
index 11154069e452b33679f0414b2cb3a5d69a2943a4..22bd113051f20c8878c1682ffb28d04f1e24bb0c 100644 (file)
@@ -50,6 +50,15 @@ class ::LastFmEvent
 end
 
 define_structure :LastFmVenue, :id, :city, :street, :postal, :country, :name, :url, :lat, :long
+class ::Struct::LastFmVenue
+  def to_s
+    str = self.name.dup
+    if self.country
+      str << " (" << [self.city, self.country].compact.join(", ") << ")"
+    end
+    str
+  end
+end
 
 class LastFmPlugin < Plugin
   include REXML
@@ -183,13 +192,23 @@ class LastFmPlugin < Plugin
       uri = "#{APIURL}method=geo.getevents&location=#{CGI.escape location.to_s}"
       emptymsg = _("no events found in %{location}") % {:location => location.to_s}
     elsif venue
-      venues = search_venue_by(:name => venue.to_s, :limit => 1)
+      begin
+        venues = search_venue_by(:name => venue.to_s, :limit => 1)
+      rescue Exception => e
+        error e
+        m.reply _("an error occurred looking for venue %{venue}: %{e}") % {
+          :venue => venue.to_s,
+          :e => e.message
+        }
+      end
+
       if venues.empty?
         m.reply _("no venue found matching %{venue}") % {:venue => venue.to_s}
         return
       end
       venue  = venues.first
       uri = "#{APIURL}method=venue.getevents&venue=#{venue.id}"
+      emptymsg = _("no events found at %{venue}") % {:venue => venue.to_s}
     elsif artist
       uri = "#{APIURL}method=artist.getevents&artist=#{CGI.escape artist.to_s}"
       emptymsg = _("no events found by %{artist}") % {:artist => artist.to_s}
@@ -736,11 +755,20 @@ class LastFmPlugin < Plugin
   end
 end
 
+event_map_options = {
+ :action => :find_events,
+ :requirements => {
+  :num => /\d+/,
+  :sort_order => /(?:asc|desc)(?:ending)?/
+ },
+ :thread => true
+}
+
 plugin = LastFmPlugin.new
-plugin.map 'lastfm [:num] event[s] in *location [sort[ed] by :sort_by] [in] [:sort_order] [order]', :action => :find_events, :requirements => { :num => /\d+/ }, :thread => true
-plugin.map 'lastfm [:num] event[s] by *who [sort[ed] by :sort_by] [in] [:sort_order] [order]', :action => :find_events, :requirements => { :num => /\d+/ }, :thread => true
-plugin.map 'lastfm [:num] event[s] at *venue [sort[ed] by :sort_by] [in] [:sort_order] [order]', :action => :find_events, :requirements => { :num => /\d+/ }, :thread => true
-plugin.map 'lastfm [:num] event[s] [for] *who [sort[ed] by :sort_by] [in] [:sort_order] [order]', :action => :find_events, :requirements => { :num => /\d+/ }, :thread => true
+plugin.map 'lastfm [:num] event[s] in *location [sort[ed] by :sort_by] [[in] :sort_order [order]]', event_map_options.dup
+plugin.map 'lastfm [:num] event[s] by *who [sort[ed] by :sort_by] [[in] :sort_order [order]]', event_map_options.dup
+plugin.map 'lastfm [:num] event[s] at *venue [sort[ed] by :sort_by] [[in] :sort_order [order]]', event_map_options.dup
+plugin.map 'lastfm [:num] event[s] [for] *who [sort[ed] by :sort_by] [[in] :sort_order [order]]', event_map_options.dup
 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