From 98781d3240b5264d25f11ae126ae06f2b6df1fa4 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Sun, 4 Nov 2007 15:11:55 +0000 Subject: factoids plugin: display multiple facts one per line, but only a limited number of them --- data/rbot/plugins/factoids.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'data/rbot/plugins') diff --git a/data/rbot/plugins/factoids.rb b/data/rbot/plugins/factoids.rb index 8ceb28f4..395ca6dc 100644 --- a/data/rbot/plugins/factoids.rb +++ b/data/rbot/plugins/factoids.rb @@ -162,15 +162,27 @@ class FactoidsPlugin < Plugin end def facts(m, params) + total = @factoids.length if params[:words].empty? - m.reply _("I know %{count} facts" % { :count => @factoids.length }) + m.reply _("I know %{total} facts" % { :total => total }) else rx = Regexp.new(params[:words].to_s, true) known = @factoids.grep(rx) if known.empty? m.reply _("I know nothing about %{words}" % params) else - m.reply known.join(" | "), :split_at => /\s+\|\s+/ + # TODO config + max_facts = 3 + len = known.length + if len > max_facts + m.reply _("%{len} out of %{total} facts refer to %{words}, I'll only show %{max}" % { + :len => len, + :total => total, + :words => params[:words].to_s, + :max => max_facts + }) + end + [max_facts, len].min.times { m.reply known.delete_one } end end end -- cgit v1.2.3