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
29 # take out the Mr. T facts if you're inserting someone's name
30 # beacuse tons of them suck, and most of them revolve around
31 # "pitying" someone or something.
32 people = FACTMAP.keys - ["mrt"]
33 who = people[rand(people.length)]
35 who = FACTMAP.keys[rand(FACTMAP.length)]
40 longwho = FACTMAP[who]
\r
42 m.reply "Who the crap is #{who}?!?!"
\r
46 matcher = %r{<h1> And now a random fact about #{longwho}...</h1>(.+?)<hr />}
\r
49 factdata = @bot.httputil.get(URI.parse("http://www.4q.cc/index.php?pid=fact&person=#{who}"))
51 m.reply "This #{longwho} fact punched my teeth in. (HTTP error)"
55 if factdata =~ matcher
56 fact = CGI::unescapeHTML($1)
57 fact.gsub!(longwho, substitute_name) if substitute_name
60 m.reply "This #{longwho} fact made my brain explode. (Parse error)"
67 plugin = ChuckNorrisPlugin.new
\r
68 plugin.map 'getfact :who', :action => 'getfact',
69 :defaults => {:who => 'random'}
70 plugin.map 'chucknorris :who', :action => 'getfact', :defaults => {:who => "chuck"}
\r
71 plugin.map 'mrt :who', :action => 'getfact', :defaults => {:who => "mrt"}
\r
72 plugin.map 'vindiesel :who', :action => 'getfact', :defaults => {:who => "vin"}
\r