From 22b2382a8a4b817b3b8b0d7812bfddafe65b73b4 Mon Sep 17 00:00:00 2001 From: Chris Gahan Date: Thu, 23 Feb 2006 15:52:16 +0000 Subject: chucknorris.rb now supports Vin Diesel and Mr. T, and is rewritten a lot. --- data/rbot/plugins/chucknorris.rb | 45 +++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/data/rbot/plugins/chucknorris.rb b/data/rbot/plugins/chucknorris.rb index 362462e6..b929b6ad 100644 --- a/data/rbot/plugins/chucknorris.rb +++ b/data/rbot/plugins/chucknorris.rb @@ -1,29 +1,50 @@ require 'uri/common' require 'cgi' + +FACTMAP = { "mrt" => "Mr\. T", + "vin" => "Vin Diesel", + "chuck" => "Chuck Norris" } class ChuckNorrisPlugin < Plugin def help(plugin, topic="") - "chucknorris => show a random chuck norris fact." + "getfact => show a random Chuck Norris or Vin Diesel or Mr. T fact || chucknorris => show a random Chuck Norris quote || vindiesel => show a random Vin Diesel quote || mrt => I pity the foo who can't figure this one out." end - - def chucknorris(m, params) - factdata = @bot.httputil.get(URI.parse('http://www.4q.cc/index.php?pid=fact&person=chuck')) + + def getfact(m, params) + who = params[:who] + m.reply "Errorn!!!" unless who + + if who == 'random' + who = FACTMAP.keys[rand(FACTMAP.length)] + end + + longwho = FACTMAP[who] + unless longwho + m.reply "Who the crap is #{who}?!?!" + return + end + + matcher = %r{

And now a random fact about #{longwho}...

(.+?)
} + + factdata = @bot.httputil.get(URI.parse("http://www.4q.cc/index.php?pid=fact&person=#{who}")) unless factdata - m.reply "This Chuck Norris fact made my brain explode. (HTTP error)" - return + m.reply "This #{longwho} fact punched my teeth in. (HTTP error)" end - - if factdata =~ %r{

And now a random fact about Chuck Norris...

(.+?)
} + if factdata =~ matcher m.reply(CGI::unescapeHTML($1)) else - m.reply "This Chuck Norris fact punched my teeth in. (Parse error)" + m.reply "This #{longwho} fact made my brain explode. (Parse error)" end - + end end -plugin = ChuckNorrisPlugin.new -plugin.map 'chucknorris' +plugin = ChuckNorrisPlugin.new +plugin.map 'getfact :who', :action => 'getfact', + :defaults => {:who => 'random'} +plugin.map 'chucknorris :who', :action => 'getfact', :defaults => {:who => "chuck"} +plugin.map 'mrt :who', :action => 'getfact', :defaults => {:who => "mrt"} +plugin.map 'vindiesel :who', :action => 'getfact', :defaults => {:who => "vin"} -- cgit v1.2.3