- substitute_name = who
- who = 'random'
- end\r
-
- # pick a random person\r
- if who == 'random'
- if substitute_name
- # take out the Mr. T facts if you're inserting someone's name
- # beacuse tons of them suck, and most of them revolve around
- # "pitying" someone or something.
- people = FACTMAP.keys - ["mrt"]
- who = people[rand(people.length)]
- else
- who = FACTMAP.keys[rand(FACTMAP.length)]
- end\r
- end\r
-
- # get the long name\r
- longwho = FACTMAP[who]\r
- unless longwho\r
- m.reply "Who the crap is #{who}?!?!"\r
- return\r
- end\r
- \r
- # get the fact
-
- m.reply "alright, let's see if I can find a good one..."
-
- tries = 0
- results = []
- loop do
-
- begin
-
- puts "[chucknorris] Try number #{tries}/#{max_tries}..."
-
- tries += 1
- fact, rating = getfact(who)
-
- if rating >= MIN_RATING
- fact.gsub!(longwho, substitute_name) if substitute_name
- m.reply "#{results.join(', ') + "... "}hrm, this one's not bad:"
- m.reply "#{fact} [rating: #{rating}]"
- return
- else
- results << "lame"
- end
-
- if tries > max_tries
- m.reply "#{results.join(', ')}... these all suck. #{PISSED_EXPRESSIONS[rand(PISSED_EXPRESSIONS.length)]}"
- return
- end
-
- rescue HTTPError
- #m.reply "This #{longwho} fact punched my teeth in. (HTTP error)"
- results << "DOH!"
- tries += 1
- rescue ParseError
- #m.reply "This #{longwho} fact made my brain explode. (Parse error)"
- results << "wtf?"
- tries += 1
- end
-