diff options
author | Tom Gilbert <tom@linuxbrit.co.uk> | 2006-01-20 09:27:18 +0000 |
---|---|---|
committer | Tom Gilbert <tom@linuxbrit.co.uk> | 2006-01-20 09:27:18 +0000 |
commit | ec65a623fa42c033f1fbd74532b6a0e2cfd8c60f (patch) | |
tree | 35d3da01252290019549c138bedf6137772f97bc /data/rbot/plugins/chucknorris.rb | |
parent | c9e5b8ee9820cafa6924617dadec567f9554aabd (diff) |
some awesome plugins from Chris Gahan >:)
Diffstat (limited to 'data/rbot/plugins/chucknorris.rb')
-rw-r--r-- | data/rbot/plugins/chucknorris.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/data/rbot/plugins/chucknorris.rb b/data/rbot/plugins/chucknorris.rb new file mode 100644 index 00000000..0eee0c17 --- /dev/null +++ b/data/rbot/plugins/chucknorris.rb @@ -0,0 +1,39 @@ +require 'rexml/document' +require 'uri/common' + +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)." + 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')) + unless factdata + m.reply "Chuck Norris' facts roundhouse kicked the internet connection and totally wasted it." + 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." + + end + + end + +end + +plugin = ChuckNorrisPlugin.new +plugin.map 'chucknorris :howmany', :defaults => {:howmany => 1}, + :requirements => {:howmany => /^-?\d+$/} |