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 | |
parent | 96733ef02eace65d3d58bc53426e400abbc72f3e (diff) |
factoids plugin: fact command (get a random fact). Remove fact command from chucknorris plugin
-rw-r--r-- | data/rbot/plugins/chucknorris.rb | 4 | ||||
-rw-r--r-- | data/rbot/plugins/factoids.rb | 26 |
2 files changed, 28 insertions, 2 deletions
diff --git a/data/rbot/plugins/chucknorris.rb b/data/rbot/plugins/chucknorris.rb index 78327ccf..bf9d70f4 100644 --- a/data/rbot/plugins/chucknorris.rb +++ b/data/rbot/plugins/chucknorris.rb @@ -43,7 +43,7 @@ class ChuckNorrisPlugin < Plugin # HELP! def help(plugin, topic="chuck") - "fact|chuck|norris|chucknorris [min_rating] => \"fact\" shows a random Chuck Norris fact (optional minimum rating from 1-10, default=6.0)." + "chuck|norris|chucknorris [min_rating] => show a random Chuck Norris fact (optional minimum rating from 1-10, default=6.0)." #\"fact [person]\" shows a fact about someone in the channel. end @@ -67,7 +67,7 @@ end plugin = ChuckNorrisPlugin.new -plugin.map 'fact :minrating', :action => 'fact', :defaults => {:minrating=>MIN_RATING} +# plugin.map 'fact :minrating', :action => 'fact', :defaults => {:minrating=>MIN_RATING} plugin.map 'chucknorris :minrating', :action => 'fact', :defaults => {:minrating=>MIN_RATING} plugin.map 'chuck :minrating', :action => 'fact', :defaults => {:minrating=>MIN_RATING} plugin.map 'norris :minrating', :action => 'fact', :defaults => {:minrating=>MIN_RATING} 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]' |