1 require 'rexml/document'
4 class ChuckNorrisPlugin < Plugin
7 def help(plugin, topic="")
8 "chucknorris [<howmany>=1] => show a random chuck norris quote, or specify <howmany> quotes you want (maximum is 6)."
11 def chucknorris(m, params)
12 howmany = params[:howmany].to_i
13 howmany = 6 if howmany > 6
15 factdata = @bot.httputil.get(URI.parse('http://www.4q.cc/chuck/rss.php'))
17 m.reply "Chuck Norris' facts roundhouse kicked the internet connection and totally wasted it."
22 doc = Document.new factdata
23 doc.get_elements('rss/channel/item')[1..howmany].each do |fact|
24 m.reply fact.elements['description'].text
27 rescue ParseException => e
28 puts "Error parsing chuck norris quote: #{e.inspect}"
29 m.reply "Chuck Norris' facts were so intense that they blew up my XML parser."
37 plugin = ChuckNorrisPlugin.new
38 plugin.map 'chucknorris :howmany', :defaults => {:howmany => 1},
39 :requirements => {:howmany => /^-?\d+$/}