4 # the 4q.cc "id => full name" mapping
\r
5 FACTMAP = { "mrt" => "Mr\. T",
\r
6 "vin" => "Vin Diesel",
\r
7 "chuck" => "Chuck Norris" }
\r
11 PISSED_EXPRESSIONS = [
12 "fuck this, i'm going to go get toed up.",
13 "screw this, i'm going to get hammered.",
14 "forget this, i'm going to iron some shirts.",
15 "disregard this, i'm going out to kill me some prostitutes.",
19 class HTTPError < Exception; end
20 class ParseError < Exception; end
23 class ChuckNorrisPlugin < Plugin
25 def help(plugin, topic="")
26 "fact [person] => \"fact\" shows a random Chuck Norris, Vin Diesel, or Mr. T fact. \"fact [person]\" shows a fact about someone in the channel. || chucknorris, chuck, norris => random Chuck Norris fact || vindiesel, vin, diesel => random Vin Diesel fact || mrt => I pity the foo who can't figure this one out."
30 raise "Unknown name: #{who}" unless FACTMAP.keys.include? who
32 factdata = @bot.httputil.get(URI.parse("http://www.4q.cc/index.php?pid=fact&person=#{who}"))
37 longwho = FACTMAP[who]
40 fact_matcher = %r{<h1> And now a random fact about #{longwho}...</h1>(.+?)<hr />}
41 rating_matcher = %r{Current Rating: <b>(\d+\.\d+)</b>}
44 if factdata =~ fact_matcher
45 fact = CGI::unescapeHTML($1)
46 if factdata =~ rating_matcher
48 puts "fact=[#{fact}], rating=[#{rating}]"
59 max_tries = (params[:tries] or "10").to_i
61 valid_people = FACTMAP.keys + ["random"]
63 # if the person wants a fact about themselves, then it'll substitute the name.
64 if valid_people.include? who
71 # pick a random person
\r
74 # take out the Mr. T facts if you're inserting someone's name
75 # beacuse tons of them suck, and most of them revolve around
76 # "pitying" someone or something.
77 people = FACTMAP.keys - ["mrt"]
78 who = people[rand(people.length)]
80 who = FACTMAP.keys[rand(FACTMAP.length)]
85 longwho = FACTMAP[who]
\r
87 m.reply "Who the crap is #{who}?!?!"
\r
93 m.reply "alright, let's see if I can find a good one..."
101 puts "[chucknorris] Try number #{tries}/#{max_tries}..."
104 fact, rating = getfact(who)
106 if rating >= MIN_RATING
107 fact.gsub!(longwho, substitute_name) if substitute_name
108 m.reply "#{results.join(', ') + "... "}hrm, this one's not bad:"
109 m.reply "#{fact} [rating: #{rating}]"
116 m.reply "#{results.join(', ')}... these all suck. #{PISSED_EXPRESSIONS[rand(PISSED_EXPRESSIONS.length)]}"
121 #m.reply "This #{longwho} fact punched my teeth in. (HTTP error)"
125 #m.reply "This #{longwho} fact made my brain explode. (Parse error)"
137 plugin = ChuckNorrisPlugin.new
\r
139 plugin.map 'fact :who :tries', :action => 'fact',
140 :defaults => {:who => 'random', :tries=>10}
142 plugin.map 'chucknorris :who', :action => 'fact', :defaults => {:who => "chuck"}
143 plugin.map 'chuck :who', :action => 'fact', :defaults => {:who => "chuck"}
144 plugin.map 'norris :who', :action => 'fact', :defaults => {:who => "chuck"}
146 plugin.map 'vindiesel :who', :action => 'fact', :defaults => {:who => "vin"}
147 plugin.map 'diesel :who', :action => 'fact', :defaults => {:who => "vin"}
148 plugin.map 'vin :who', :action => 'fact', :defaults => {:who => "vin"}
150 plugin.map 'mrt :who', :action => 'fact', :defaults => {:who => "mrt"}