\r
require 'rss'\r
\r
-# Add support for Slashdot namespace in RDF. The code is just an adaptation of\r
-# the DublinCore code.\r
module ::RSS\r
\r
+ # Make an 'unique' ID for a given item, based on appropriate bot options\r
+ # Currently only suppored is bot.config['rss.show_updated']: when true, the\r
+ # description is included in the uid hashing, otherwise it's not\r
+ #\r
+ def RSS.item_uid_for_bot(item, opts={})\r
+ options = { :show_updated => true}.merge(opts)\r
+ desc = options[:show_updated] ? item.description : nil\r
+ [item.title, item.link, desc].hash\r
+ end\r
+\r
+ # Add support for Slashdot namespace in RDF. The code is just an adaptation\r
+ # of the DublinCore code.\r
unless defined?(SLASH_PREFIX)\r
SLASH_PREFIX = 'slash'\r
SLASH_URI = "http://purl.org/rss/1.0/modules/slash/"\r
\r
class RSSFeedsPlugin < Plugin\r
BotConfig.register BotConfigIntegerValue.new('rss.head_max',\r
- :default => 30, :validate => Proc.new{|v| v > 0 && v < 200},\r
+ :default => 100, :validate => Proc.new{|v| v > 0 && v < 200},\r
:desc => "How many characters to use of a RSS item header")\r
\r
BotConfig.register BotConfigIntegerValue.new('rss.text_max',\r
- :default => 90, :validate => Proc.new{|v| v > 0 && v < 400},\r
+ :default => 200, :validate => Proc.new{|v| v > 0 && v < 400},\r
:desc => "How many characters to use of a RSS item text")\r
\r
BotConfig.register BotConfigIntegerValue.new('rss.thread_sleep',\r
:default => 300, :validate => Proc.new{|v| v > 30},\r
:desc => "How many seconds to sleep before checking RSS feeds again")\r
\r
+ BotConfig.register BotConfigBooleanValue.new('rss.show_updated',\r
+ :default => true,\r
+ :desc => "Whether feed items for which the description was changed should be shown as new")\r
+\r
# We used to save the Mutex with the RssBlob, which was idiotic. And\r
# since Mutexes dumped in one version might not be resotrable in another,\r
# we need a few tricks to be able to restore data from other versions of Ruby\r
}\r
\r
@feeds = @registry[:feeds]\r
+ raise unless @feeds\r
\r
@registry.recovery = nil\r
\r
debug "Stopping watch #{handle}"\r
@bot.timer.remove(@watch[handle])\r
@watch.delete(handle)\r
- rescue => e\r
+ rescue Exception => e\r
report_problem("Failed to stop watch for #{handle}", e, nil)\r
end\r
end\r
reply = "no feeds found"\r
reply << " matching #{wanted}" if wanted\r
end\r
- m.reply reply\r
+ m.reply reply, :max_lines => reply.length\r
end\r
\r
def watched_rss(m, params)\r
unless fetchRss(feed)\r
failures += 1\r
else\r
- if first_run or (oldxml and oldxml == feed.xml)\r
+ if first_run\r
+ debug "first run for #{feed}, getting items"\r
+ parseRss(feed)\r
+ elsif oldxml and oldxml == feed.xml\r
debug "xml for #{feed} didn't change"\r
failures -= 1 if failures > 0\r
else\r
parseRss(feed)\r
failures -= 1 if failures > 0\r
else\r
- otxt = feed.items.map { |item| item.to_s }\r
+ # This one is used for debugging\r
+ otxt = []\r
+\r
+ # These are used for checking new items vs old ones\r
+ uid_opts = { :show_updated => @bot.config['rss.show_updated'] }\r
+ oids = Set.new feed.items.map { |item|\r
+ uid = RSS.item_uid_for_bot(item, uid_opts)\r
+ otxt << item.to_s\r
+ debug [uid, item].inspect\r
+ debug [uid, otxt.last].inspect\r
+ uid\r
+ }\r
+\r
unless parseRss(feed)\r
debug "no items in feed #{feed}"\r
failures += 1\r
else\r
debug "Checking if new items are available for #{feed}"\r
failures -= 1 if failures > 0\r
+ # debug "Old:"\r
+ # debug oldxml\r
+ # debug "New:"\r
+ # debug feed.xml\r
+\r
dispItems = feed.items.reject { |item|\r
- otxt.include?(item.to_s)\r
+ uid = RSS.item_uid_for_bot(item, uid_opts)\r
+ txt = item.to_s\r
+ if oids.include?(uid)\r
+ debug "rejecting old #{uid} #{item.inspect}"\r
+ debug [uid, txt].inspect\r
+ true\r
+ else\r
+ debug "accepting new #{uid} #{item.inspect}"\r
+ debug [uid, txt].inspect\r
+ warn "same text! #{txt}" if otxt.include?(txt)\r
+ false\r
+ end\r
}\r
+\r
if dispItems.length > 0\r
debug "Found #{dispItems.length} new items in #{feed}"\r
# When displaying watched feeds, publish them from older to newer\r
if opts.key?(:date) && opts[:date]\r
if item.respond_to?(:pubDate) \r
if item.pubDate.class <= Time\r
- date = item.pubDate.strftime("%Y/%m/%d %H.%M.%S")\r
+ date = item.pubDate.strftime("%Y/%m/%d %H:%M")\r
else\r
date = item.pubDate.to_s\r
end\r
elsif item.respond_to?(:date)\r
if item.date.class <= Time\r
- date = item.date.strftime("%Y/%m/%d %H.%M.%S")\r
+ date = item.date.strftime("%Y/%m/%d %H:%M")\r
else\r
date = item.date.to_s\r
end\r
end\r
end\r
\r
- title = "#{Bold}#{item.title.ircify_html}#{Bold}" if item.title\r
+ title = "#{Bold}#{item.title.ircify_html :limit => @bot.config['rss.head_max']}#{Bold}" if item.title\r
\r
- desc = item.description.ircify_html if item.description\r
+ desc = item.description.ircify_html(:limit => @bot.config['rss.text_max'], :a_href => :link_out) if item.description\r
\r
link = item.link.chomp if item.link\r
\r
debug item.inspect\r
- category = item.dc_subject rescue item.category rescue nil\r
+ category = item.dc_subject rescue item.category.content rescue nil\r
+ category = nil if category and category.empty?\r
author = item.dc_creator rescue item.author rescue nil\r
+ author = nil if author and author.empty?\r
\r
line1 = nil\r
line2 = nil\r
at = ((item.title && item.link) ? ' @ ' : '')\r
case feed.type\r
when 'blog'\r
+ author << " " if author\r
abt = category ? "about #{category} " : ""\r
- line1 = "#{handle}#{date}#{author} blogged #{abt}at #{link}"\r
+ line1 = "#{handle}#{date}#{author}blogged #{abt}at #{link}"\r
line2 = "#{handle}#{title} - #{desc}"\r
when 'forum'\r
line1 = "#{handle}#{date}#{title}#{at}#{link}"\r
plugin.map 'rss forcereplace :handle :url :type',\r
:action => 'forcereplace_rss',\r
:defaults => {:type => nil}\r
+plugin.map 'rss watch :handle [in :chan]',\r
+ :action => 'watch_rss',\r
+ :defaults => {:url => nil, :type => nil}\r
plugin.map 'rss watch :handle :url :type [in :chan]',\r
:action => 'watch_rss',\r
:defaults => {:url => nil, :type => nil}\r