require 'rubygems' require 'hpricot' # <@tango_> unfo-, two notes about your plugin # <@tango_> (1) why not use @bot.httputil.get(uri) instead of open(uri)? # <@tango_> (2) :thread => yes to the method so it doesn't lock the bot while retrieving class QdbPlugin < Plugin def help(plugin, topic="") "qdb => fetch qdb quote by id" end def retrieve(m) request = m.params url = "http://www.qdb.us/#{request}" begin doc = Hpricot(@bot.httputil.get(url)) # (1) quote = (doc/"table[@class='quote']/tr[2]/td[1]/p").text.split("\n") if quote.size <= 5 quote.each {|line| m.reply line } else m.reply "quote too long (%s lines), see for yerself: %s" % [quote.size, url] end rescue => e m.reply "Fail" end end def privmsg(m) retrieve(m) end end plugin = QdbPlugin.new plugin.map "qdb *request", :action => 'retrieve', :thread => "yes" # (2)