summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-11-04 15:13:35 +0000
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-11-04 15:13:35 +0000
commit90f968e96fe0bc59924f41e6d61e9efee871c003 (patch)
tree0cb27fb499a48714d1f8696b60d1e21ddad64331
parent0de0f89e3e50b77e6fb9f7c400a7b41605d7bbf2 (diff)
factoids plugin: display (selected, random) multiple facts in a single line, but in long form
-rw-r--r--data/rbot/plugins/factoids.rb28
1 files changed, 20 insertions, 8 deletions
diff --git a/data/rbot/plugins/factoids.rb b/data/rbot/plugins/factoids.rb
index 78319fdc..5d6401ef 100644
--- a/data/rbot/plugins/factoids.rb
+++ b/data/rbot/plugins/factoids.rb
@@ -180,6 +180,15 @@ class FactoidsPlugin < Plugin
end
end
+ def long_fact(fact,index=nil,total=@factoids.length)
+ idx = index || @factoids.index(fact)+1
+ _("fact #%{idx} of %{total}: %{fact}" % {
+ :idx => idx,
+ :total => total,
+ :fact => fact.to_s(:meta => true)
+ })
+ end
+
def facts(m, params)
total = @factoids.length
if params[:words].empty?
@@ -187,11 +196,12 @@ class FactoidsPlugin < Plugin
else
rx = Regexp.new(params[:words].to_s, true)
known = @factoids.grep(rx)
+ reply = []
if known.empty?
- m.reply _("I know nothing about %{words}" % params)
+ reply << _("I know nothing about %{words}" % params)
else
# TODO config
- max_facts = 3
+ max_facts = 5
len = known.length
if len > max_facts
m.reply _("%{len} out of %{total} facts refer to %{words}, I'll only show %{max}" % {
@@ -200,9 +210,15 @@ class FactoidsPlugin < Plugin
:words => params[:words].to_s,
:max => max_facts
})
+ while known.length > max_facts
+ known.delete_one
+ end
end
- [max_facts, len].min.times { m.reply known.delete_one }
+ known.each { |f|
+ reply << long_fact(f)
+ }
end
+ m.reply reply.join(" -- ")
end
end
@@ -236,11 +252,7 @@ class FactoidsPlugin < Plugin
fact = known.pick_one
idx = @factoids.index(fact)+1
end
- m.reply _("fact #%{idx} of %{total}: %{fact}" % {
- :idx => idx,
- :total => total,
- :fact => fact.to_s(:meta => true)
- })
+ m.reply long_fact(fact, idx, total)
end
def edit_fact(m, params)