1 # Hacked up slashdot headlines plugin...
4 require 'rexml/document'
7 class DiggPlugin < Plugin
9 def help(plugin, topic="")
10 "digg [<max>=5] => show digg headlines, [<max>=5] => return up to <max> headlines (use a negative number to show all the headlines on one line)"
14 max = params[:limit].to_i
16 xml = @bot.httputil.get_cached(URI.parse("http://digg.com/rss/index.xml"))
18 m.reply "digg news parse failed"
21 doc = Document.new xml
23 m.reply "digg news parse failed (invalid xml)"
34 doc.elements.each("rss/channel/item") {|e|
35 matches << [ e.elements["title"].text,
36 Time.parse(e.elements["pubDate"].text).strftime('%a @ %I:%M%p') ]
41 m.reply matches.collect{|mat| mat[0]}.join(" | ")
44 m.reply sprintf("%42s | %13s", mat[0][0,42], mat[1])
49 plugin = DiggPlugin.new
50 plugin.map 'digg :limit', :defaults => {:limit => 5},
51 :requirements => {:limit => /^-?\d+$/}