diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2007-11-04 15:11:55 +0000 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2007-11-04 15:11:55 +0000 |
commit | 98781d3240b5264d25f11ae126ae06f2b6df1fa4 (patch) | |
tree | 926a778aeaaef9963eefa3a2d1c16051db3eea0c | |
parent | 2327431c922faba63817bff7353290ba3b7cbcf4 (diff) |
factoids plugin: display multiple facts one per line, but only a limited number of them
-rw-r--r-- | data/rbot/plugins/factoids.rb | 16 |
1 files changed, 14 insertions, 2 deletions
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 |