4 FACTMAP = { "mrt" => "Mr\. T",
\r
5 "vin" => "Vin Diesel",
\r
6 "chuck" => "Chuck Norris" }
\r
8 class ChuckNorrisPlugin < Plugin
10 def help(plugin, topic="")
11 "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."
14 def getfact(m, params)
\r
16 m.reply "Errorn!!!" unless who
\r
19 who = FACTMAP.keys[rand(FACTMAP.length)]
\r
22 longwho = FACTMAP[who]
\r
24 m.reply "Who the crap is #{who}?!?!"
\r
28 matcher = %r{<h1> And now a random fact about #{longwho}...</h1>(.+?)<hr />}
\r
30 factdata = @bot.httputil.get(URI.parse("http://www.4q.cc/index.php?pid=fact&person=#{who}"))
32 m.reply "This #{longwho} fact punched my teeth in. (HTTP error)"
35 if factdata =~ matcher
36 m.reply(CGI::unescapeHTML($1))
38 m.reply "This #{longwho} fact made my brain explode. (Parse error)"
45 plugin = ChuckNorrisPlugin.new
\r
46 plugin.map 'getfact :who', :action => 'getfact',
47 :defaults => {:who => 'random'}
48 plugin.map 'chucknorris :who', :action => 'getfact', :defaults => {:who => "chuck"}
\r
49 plugin.map 'mrt :who', :action => 'getfact', :defaults => {:who => "mrt"}
\r
50 plugin.map 'vindiesel :who', :action => 'getfact', :defaults => {:who => "vin"}
\r