1 # bash.org xml plugin for rbot
2 # by Robin Kearney (robin@riviera.org.uk)
4 # its a bit of a quick hack, but it works for us :)
6 require 'rexml/document'
9 class BashPlugin < Plugin
11 def help(plugin, topic="")
12 "bash => print a random quote from bash.org, bash quote_id => print that quote id from bash.org, bash latest => print the latest quote from bash.org (currently broken, need to get josh@bash.org to fix the xml)"
15 if m.params && m.params =~ /^([-\d]+)$/
18 elsif(m.params == "latest")
28 xml = @bot.httputil.get("http://bash.org/xml/?" + id + "&num=1")
30 xml = @bot.httputil.get("http://bash.org/xml/?latest&num=1")
32 xml = @bot.httputil.get("http://bash.org/xml/?random&num=1",
36 m.reply "bash.org rss parse failed"
39 doc = Document.new xml
41 m.reply "bash.org rss parse failed"
44 doc.elements.each("*/item") {|e|
46 reply = e.elements["title"].text.gsub(/QDB: /,"") + " " + e.elements["link"].text.gsub(/QDB: /,"") + "\n"
47 reply = reply + e.elements["description"].text.gsub(/\<br \/\>/, "\n")
49 reply = e.elements["title"].text.gsub(/QDB: /,"") + " " + e.elements["link"].text.gsub(/QDB: /,"") + "\n"
50 reply = reply + e.elements["description"].text.gsub(/\<br \/\>/, "\n")
56 plugin = BashPlugin.new
57 plugin.register("bash")