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 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."
14 def getfact(m, params)
16 valid_people = FACTMAP.keys + ["random"]
18 # if the person wants a fact about themselves, then it'll substitute the name.
19 if valid_people.include? who
26 # pick a random person
\r
28 who = FACTMAP.keys[rand(FACTMAP.length)]
\r
32 longwho = FACTMAP[who]
\r
34 m.reply "Who the crap is #{who}?!?!"
\r
38 matcher = %r{<h1> And now a random fact about #{longwho}...</h1>(.+?)<hr />}
\r
41 factdata = @bot.httputil.get(URI.parse("http://www.4q.cc/index.php?pid=fact&person=#{who}"))
43 m.reply "This #{longwho} fact punched my teeth in. (HTTP error)"
47 if factdata =~ matcher
48 fact = CGI::unescapeHTML($1)
49 fact.gsub!(longwho, substitute_name) if substitute_name
52 m.reply "This #{longwho} fact made my brain explode. (Parse error)"
59 plugin = ChuckNorrisPlugin.new
\r
60 plugin.map 'getfact :who', :action => 'getfact',
61 :defaults => {:who => 'random'}
62 plugin.map 'chucknorris :who', :action => 'getfact', :defaults => {:who => "chuck"}
\r
63 plugin.map 'mrt :who', :action => 'getfact', :defaults => {:who => "mrt"}
\r
64 plugin.map 'vindiesel :who', :action => 'getfact', :defaults => {:who => "vin"}
\r