"slashdot search <string> [<max>=4] => search slashdot for <string>, slashdot [<max>=4] => return up to <max> slashdot headlines (use negative max to return that many headlines, but all on one line.)"
end
class SlashdotPlugin < Plugin
include REXML
def help(plugin, topic="")
"slashdot search <string> [<max>=4] => search slashdot for <string>, slashdot [<max>=4] => return up to <max> slashdot headlines (use negative max to return that many headlines, but all on one line.)"
end
- def privmsg(m)
- if m.params && m.params =~ /^search\s+(.*)\s+(\d+)$/
- search = $1
- limit = $2.to_i
- search_slashdot m, search, limit
- elsif m.params && m.params =~ /^search\s+(.*)$/
- search = $1
- search_slashdot m, search
- elsif m.params && m.params =~ /^([-\d]+)$/
- limit = $1.to_i
- slashdot m, limit
- else
- slashdot m
- end
- end
- def search_slashdot(m, search, max=4)
- begin
- xml = @bot.httputil.get(URI.parse("http://slashdot.org/search.pl?content_type=rss&query=#{URI.escape(search)}"))
- rescue URI::InvalidURIError, URI::BadURIError => e
- m.reply "illegal search string #{search}"
- return
- end
+ def search_slashdot(m, params)
+ max = params[:limit].to_i
+ search = params[:search].to_s
+
+ xml = @bot.httputil.get("http://slashdot.org/search.pl?content_type=rss&query=#{CGI.escape(search)}")