summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Gahan <chris@ill-logic.com>2006-02-22 00:14:43 +0000
committerChris Gahan <chris@ill-logic.com>2006-02-22 00:14:43 +0000
commitac4141a466cc992539ba076d1188cfa15b35ab6f (patch)
treecfdb8f5ccc41e8619037c78858d39125151227be
parentf4731683240a6bd9de5dc8cc075cad4700d77c10 (diff)
A fixed chuck norris plugin. (The XML feed was disabled, so this one just scrapes the website.)
-rw-r--r--data/rbot/plugins/chucknorris.rb28
1 files changed, 9 insertions, 19 deletions
diff --git a/data/rbot/plugins/chucknorris.rb b/data/rbot/plugins/chucknorris.rb
index 0eee0c17..362462e6 100644
--- a/data/rbot/plugins/chucknorris.rb
+++ b/data/rbot/plugins/chucknorris.rb
@@ -1,33 +1,24 @@
-require 'rexml/document'
require 'uri/common'
+require 'cgi'
class ChuckNorrisPlugin < Plugin
- include REXML
def help(plugin, topic="")
- "chucknorris [<howmany>=1] => show a random chuck norris quote, or specify <howmany> quotes you want (maximum is 6)."
+ "chucknorris => show a random chuck norris fact."
end
def chucknorris(m, params)
- howmany = params[:howmany].to_i
- howmany = 6 if howmany > 6
-
- factdata = @bot.httputil.get(URI.parse('http://www.4q.cc/chuck/rss.php'))
+ factdata = @bot.httputil.get(URI.parse('http://www.4q.cc/index.php?pid=fact&person=chuck'))
unless factdata
- m.reply "Chuck Norris' facts roundhouse kicked the internet connection and totally wasted it."
+ m.reply "This Chuck Norris fact made my brain explode. (HTTP error)"
return
end
- begin
- doc = Document.new factdata
- doc.get_elements('rss/channel/item')[1..howmany].each do |fact|
- m.reply fact.elements['description'].text
- end
-
- rescue ParseException => e
- puts "Error parsing chuck norris quote: #{e.inspect}"
- m.reply "Chuck Norris' facts were so intense that they blew up my XML parser."
+ if factdata =~ %r{<h1> And now a random fact about Chuck Norris...</h1>(.+?)<hr />}
+ m.reply(CGI::unescapeHTML($1))
+ else
+ m.reply "This Chuck Norris fact punched my teeth in. (Parse error)"
end
end
@@ -35,5 +26,4 @@ class ChuckNorrisPlugin < Plugin
end
plugin = ChuckNorrisPlugin.new
-plugin.map 'chucknorris :howmany', :defaults => {:howmany => 1},
- :requirements => {:howmany => /^-?\d+$/}
+plugin.map 'chucknorris'