From 899c42e1b879cb5b1e6f8203cd7ff53ed6d1a45b Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Fri, 6 Apr 2007 11:39:25 +0000 Subject: lastfm plugin: number of events to be displayed can now be configured --- data/rbot/plugins/lastfm.rb | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'data/rbot') diff --git a/data/rbot/plugins/lastfm.rb b/data/rbot/plugins/lastfm.rb index 49ef9fed..46b140ff 100644 --- a/data/rbot/plugins/lastfm.rb +++ b/data/rbot/plugins/lastfm.rb @@ -35,13 +35,19 @@ class ::LastFmEvent end class LastFmPlugin < Plugin + BotConfig.register BotConfigIntegerValue.new('lastfm.max_events', + :default => 25, :validate => Proc.new{|v| v > 1}, + :desc => "Maximum number of events to display.") + BotConfig.register BotConfigIntegerValue.new('lastfm.default_events', + :default => 3, :validate => Proc.new{|v| v > 1}, + :desc => "Default number of events to display.") LASTFM = "http://www.last.fm" def help(plugin, topic="") case topic.intern when :event, :events - "lastfm events in => show information on events in or near . lastfm events by => show information on events by " + "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 #{@bot.config['lastfm.default_events']} and cannot be higher than #{@bot.config['lastfm.max_events']}" when :artist, :group "lastfm artist => show information on artist/group from last.fm" when :song, :track @@ -54,6 +60,9 @@ class LastFmPlugin < Plugin end def find_event(m, params) + num = params[:num] || @bot.config['lastfm.default_events'] + num = num.to_i.clip(1, @bot.config['lastfm.max_events']) + location = artist = nil location = params[:location].to_s if params[:location] artist = params[:who].to_s if params[:who] @@ -101,10 +110,10 @@ class LastFmPlugin < Plugin } # debug events.inspect - events[0..2].each { |event| + events[0...num].each { |event| disp_events << event.to_s } - m.reply disp_events.join(' | ') + m.reply disp_events.join(' | '), :split_at => /\s+\|\s+/ else m.reply "No events found #{spec}" return @@ -174,9 +183,9 @@ class LastFmPlugin < Plugin end plugin = LastFmPlugin.new -plugin.map 'lastfm event[s] in *location', :action => :find_event -plugin.map 'lastfm event[s] by *who', :action => :find_event -plugin.map 'lastfm event[s] [for] *who', :action => :find_event +plugin.map 'lastfm [:num] event[s] in *location', :action => :find_event, :requirements => { :num => /\d+/ } +plugin.map 'lastfm [:num] event[s] by *who', :action => :find_event, :requirements => { :num => /\d+/ } +plugin.map 'lastfm [:num] event[s] [for] *who', :action => :find_event, :requirements => { :num => /\d+/ } plugin.map 'lastfm artist *who', :action => :find_artist plugin.map 'lastfm group *who', :action => :find_artist plugin.map 'lastfm track *dunno', :action => :find_track -- cgit v1.2.3