diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2007-11-04 01:24:06 +0000 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2007-11-04 01:24:06 +0000 |
commit | 1f2a7ba69a4aa116924b94eb4af74e2301a787a8 (patch) | |
tree | c06b07c294be9ce8cd6dea061218388114f2f46d /data/rbot/plugins/factoids.rb | |
parent | 96733ef02eace65d3d58bc53426e400abbc72f3e (diff) |
factoids plugin: fact command (get a random fact). Remove fact command from chucknorris plugin
Diffstat (limited to 'data/rbot/plugins/factoids.rb')
-rw-r--r-- | data/rbot/plugins/factoids.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/data/rbot/plugins/factoids.rb b/data/rbot/plugins/factoids.rb index eee1dfaa..d9966fa8 100644 --- a/data/rbot/plugins/factoids.rb +++ b/data/rbot/plugins/factoids.rb @@ -149,9 +149,35 @@ class FactoidsPlugin < Plugin end end + def fact(m, params) + known = nil + if params[:words].empty? + if @factoids.empty? + m.reply _("I know nothing") + return + end + known = @factoids + else + rx = Regexp.new(params[:words].to_s, true) + known = @factoids.grep(rx) + if known.empty? + m.reply _("I know nothing about %{words}" % params) + return + end + end + fact = known.pick_one + idx = @factoids.index(fact)+1 + m.reply _("fact %{idx}/%{total}: %{fact}" % { + :idx => idx, + :total => @factoids.length, + :fact => fact + }) + end + end plugin = FactoidsPlugin.new plugin.map 'learn that *stuff' plugin.map 'forget that *stuff' plugin.map 'facts [about *words]' +plugin.map 'fact [about *words]' |