diff options
author | Chris Gahan <chris@ill-logic.com> | 2006-02-25 20:08:14 +0000 |
---|---|---|
committer | Chris Gahan <chris@ill-logic.com> | 2006-02-25 20:08:14 +0000 |
commit | 037a917e382e5f80ffc7be5e94e614dbe08340e2 (patch) | |
tree | 3e4bd42d3690d7b904a006a89da8a43201ef7523 /data/rbot/plugins | |
parent | 22b2382a8a4b817b3b8b0d7812bfddafe65b73b4 (diff) |
You can now add the nick of someone in the channel to get a fact about them.
Diffstat (limited to 'data/rbot/plugins')
-rw-r--r-- | data/rbot/plugins/chucknorris.rb | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/data/rbot/plugins/chucknorris.rb b/data/rbot/plugins/chucknorris.rb index b929b6ad..5c64de69 100644 --- a/data/rbot/plugins/chucknorris.rb +++ b/data/rbot/plugins/chucknorris.rb @@ -8,32 +8,46 @@ FACTMAP = { "mrt" => "Mr\. T", class ChuckNorrisPlugin < Plugin def help(plugin, topic="") - "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." + "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." end - def getfact(m, params)
- who = params[:who]
- m.reply "Errorn!!!" unless who
-
+ def getfact(m, params) + who = params[:who] + valid_people = FACTMAP.keys + ["random"] + + # if the person wants a fact about themselves, then it'll substitute the name. + if valid_people.include? who + substitute_name = nil + else + substitute_name = who + who = 'random' + end
+ + # pick a random person
if who == 'random'
- who = FACTMAP.keys[rand(FACTMAP.length)]
+ who = FACTMAP.keys[rand(FACTMAP.length)]
end
-
+ + # get the long name
longwho = FACTMAP[who]
unless longwho
- m.reply "Who the crap is #{who}?!?!"
- return
+ m.reply "Who the crap is #{who}?!?!"
+ return
end
matcher = %r{<h1> And now a random fact about #{longwho}...</h1>(.+?)<hr />}
+ # get the fact factdata = @bot.httputil.get(URI.parse("http://www.4q.cc/index.php?pid=fact&person=#{who}")) unless factdata m.reply "This #{longwho} fact punched my teeth in. (HTTP error)" end + # parse the fact if factdata =~ matcher - m.reply(CGI::unescapeHTML($1)) + fact = CGI::unescapeHTML($1) + fact.gsub!(longwho, substitute_name) if substitute_name + m.reply fact else m.reply "This #{longwho} fact made my brain explode. (Parse error)" end |