From 037a917e382e5f80ffc7be5e94e614dbe08340e2 Mon Sep 17 00:00:00 2001 From: Chris Gahan Date: Sat, 25 Feb 2006 20:08:14 +0000 Subject: You can now add the nick of someone in the channel to get a fact about them. --- data/rbot/plugins/chucknorris.rb | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) (limited to 'data/rbot/plugins') diff --git a/data/rbot/plugins/chucknorris.rb b/data/rbot/plugins/chucknorris.rb index b929b6ad..5c64de69 100644 --- a/data/rbot/plugins/chucknorris.rb +++ b/data/rbot/plugins/chucknorris.rb @@ -8,32 +8,46 @@ FACTMAP = { "mrt" => "Mr\. T", class ChuckNorrisPlugin < Plugin def help(plugin, topic="") - "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." + "getfact => show a random fact, or append someone's name to get a fact about that person (eg. !getfact epitron)|| 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 getfact(m, params) - who = params[:who] - m.reply "Errorn!!!" unless who - + def getfact(m, params) + who = params[:who] + valid_people = FACTMAP.keys + ["random"] + + # if the person wants a fact about themselves, then it'll substitute the name. + if valid_people.include? who + substitute_name = nil + else + substitute_name = who + who = 'random' + end + + # pick a random person if who == 'random' - who = FACTMAP.keys[rand(FACTMAP.length)] + who = FACTMAP.keys[rand(FACTMAP.length)] end - + + # get the long name longwho = FACTMAP[who] unless longwho - m.reply "Who the crap is #{who}?!?!" - return + m.reply "Who the crap is #{who}?!?!" + return end matcher = %r{

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

(.+?)
} + # get the fact factdata = @bot.httputil.get(URI.parse("http://www.4q.cc/index.php?pid=fact&person=#{who}")) unless factdata m.reply "This #{longwho} fact punched my teeth in. (HTTP error)" end + # parse the fact if factdata =~ matcher - m.reply(CGI::unescapeHTML($1)) + fact = CGI::unescapeHTML($1) + fact.gsub!(longwho, substitute_name) if substitute_name + m.reply fact else m.reply "This #{longwho} fact made my brain explode. (Parse error)" end -- cgit v1.2.3