1 require 'rexml/document'
4 class SlashdotPlugin < Plugin
6 def help(plugin, topic="")
7 "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.)"
10 if m.params && m.params =~ /^search\s+(.*)\s+(\d+)$/
13 search_slashdot m, search, limit
14 elsif m.params && m.params =~ /^search\s+(.*)$/
16 search_slashdot m, search
17 elsif m.params && m.params =~ /^([-\d]+)$/
25 def search_slashdot(m, search, max=4)
27 xml = Utils.http_get("http://slashdot.org/search.pl?content_type=rss&query=#{URI.escape(search)}")
28 rescue URI::InvalidURIError, URI::BadURIError => e
29 m.reply "illegal search string #{search}"
33 m.reply "search for #{search} failed"
36 doc = Document.new xml
38 m.reply "search for #{search} failed"
43 doc.elements.each("*/item") {|e|
44 desc = e.elements["title"].text
45 desc.gsub!(/(.{150}).*/, '\1..')
46 reply = sprintf("%s | %s", e.elements["link"].text, desc)
53 def slashdot(m, max=4)
54 xml = Utils.http_get("http://slashdot.org/slashdot.xml")
56 m.reply "slashdot news parse failed"
59 doc = Document.new xml
61 m.reply "slashdot news parse failed"
72 doc.elements.each("*/story") {|e|
73 matches << [ e.elements["title"].text,
74 e.elements["author"].text,
75 e.elements["time"].text.gsub(/\d{4}-(\d{2})-(\d{2})/, "\\2/\\1").gsub(/:\d\d$/, "") ]
80 m.reply matches.collect{|mat| mat[0]}.join(" | ")
83 m.reply sprintf("%36s | %8s | %8s", mat[0][0,36], mat[1][0,8], mat[2])
88 plugin = SlashdotPlugin.new
89 plugin.register("slashdot")