X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Frss.rb;h=ed37965036ff4abfadd6fe60fba50bb4ab32f671;hb=69db4133c5ccfa41c35b43c67fce1d5ff640bfd5;hp=8e157b86b9fb05780a1a498270b38cedd9acf304;hpb=f70ef9f1908c3ac4a4959debc156aa6ae012d567;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/rss.rb b/data/rbot/plugins/rss.rb index 8e157b86..ed379650 100644 --- a/data/rbot/plugins/rss.rb +++ b/data/rbot/plugins/rss.rb @@ -16,8 +16,6 @@ require 'rss' -# Add support for Slashdot namespace in RDF. The code is just an adaptation of -# the DublinCore code. module ::RSS # Make an 'unique' ID for a given item, based on appropriate bot options @@ -30,6 +28,8 @@ module ::RSS [item.title, item.link, desc].hash end + # Add support for Slashdot namespace in RDF. The code is just an adaptation + # of the DublinCore code. unless defined?(SLASH_PREFIX) SLASH_PREFIX = 'slash' SLASH_URI = "http://purl.org/rss/1.0/modules/slash/" @@ -230,11 +230,11 @@ end class RSSFeedsPlugin < Plugin BotConfig.register BotConfigIntegerValue.new('rss.head_max', - :default => 30, :validate => Proc.new{|v| v > 0 && v < 200}, + :default => 100, :validate => Proc.new{|v| v > 0 && v < 200}, :desc => "How many characters to use of a RSS item header") BotConfig.register BotConfigIntegerValue.new('rss.text_max', - :default => 90, :validate => Proc.new{|v| v > 0 && v < 400}, + :default => 200, :validate => Proc.new{|v| v > 0 && v < 400}, :desc => "How many characters to use of a RSS item text") BotConfig.register BotConfigIntegerValue.new('rss.thread_sleep', @@ -289,6 +289,7 @@ class RSSFeedsPlugin < Plugin } @feeds = @registry[:feeds] + raise unless @feeds @registry.recovery = nil @@ -336,7 +337,7 @@ class RSSFeedsPlugin < Plugin debug "Stopping watch #{handle}" @bot.timer.remove(@watch[handle]) @watch.delete(handle) - rescue => e + rescue Exception => e report_problem("Failed to stop watch for #{handle}", e, nil) end end @@ -463,7 +464,7 @@ class RSSFeedsPlugin < Plugin reply = "no feeds found" reply << " matching #{wanted}" if wanted end - m.reply reply + m.reply reply, :max_lines => reply.length end def watched_rss(m, params) @@ -668,7 +669,10 @@ class RSSFeedsPlugin < Plugin unless fetchRss(feed) failures += 1 else - if first_run or (oldxml and oldxml == feed.xml) + if first_run + debug "first run for #{feed}, getting items" + parseRss(feed) + elsif oldxml and oldxml == feed.xml debug "xml for #{feed} didn't change" failures -= 1 if failures > 0 else @@ -685,6 +689,7 @@ class RSSFeedsPlugin < Plugin oids = Set.new feed.items.map { |item| uid = RSS.item_uid_for_bot(item, uid_opts) otxt << item.to_s + debug [uid, item].inspect debug [uid, otxt.last].inspect uid } @@ -695,6 +700,10 @@ class RSSFeedsPlugin < Plugin else debug "Checking if new items are available for #{feed}" failures -= 1 if failures > 0 + # debug "Old:" + # debug oldxml + # debug "New:" + # debug feed.xml dispItems = feed.items.reject { |item| uid = RSS.item_uid_for_bot(item, uid_opts) @@ -752,13 +761,13 @@ class RSSFeedsPlugin < Plugin if opts.key?(:date) && opts[:date] if item.respond_to?(:pubDate) if item.pubDate.class <= Time - date = item.pubDate.strftime("%Y/%m/%d %H.%M.%S") + date = item.pubDate.strftime("%Y/%m/%d %H:%M") else date = item.pubDate.to_s end elsif item.respond_to?(:date) if item.date.class <= Time - date = item.date.strftime("%Y/%m/%d %H.%M.%S") + date = item.date.strftime("%Y/%m/%d %H:%M") else date = item.date.to_s end @@ -769,15 +778,17 @@ class RSSFeedsPlugin < Plugin end end - title = "#{Bold}#{item.title.ircify_html}#{Bold}" if item.title + title = "#{Bold}#{item.title.ircify_html :limit => @bot.config['rss.head_max']}#{Bold}" if item.title - desc = item.description.ircify_html(:a_href => :link_out) if item.description + desc = item.description.ircify_html(:limit => @bot.config['rss.text_max'], :a_href => :link_out) if item.description link = item.link.chomp if item.link debug item.inspect - category = item.dc_subject rescue item.category rescue nil + category = item.dc_subject rescue item.category.content rescue nil + category = nil if category and category.empty? author = item.dc_creator rescue item.author rescue nil + author = nil if author and author.empty? line1 = nil line2 = nil @@ -785,8 +796,9 @@ class RSSFeedsPlugin < Plugin at = ((item.title && item.link) ? ' @ ' : '') case feed.type when 'blog' + author << " " if author abt = category ? "about #{category} " : "" - line1 = "#{handle}#{date}#{author} blogged #{abt}at #{link}" + line1 = "#{handle}#{date}#{author}blogged #{abt}at #{link}" line2 = "#{handle}#{title} - #{desc}" when 'forum' line1 = "#{handle}#{date}#{title}#{at}#{link}" @@ -933,6 +945,9 @@ plugin.map 'rss replace :handle :url :type', plugin.map 'rss forcereplace :handle :url :type', :action => 'forcereplace_rss', :defaults => {:type => nil} +plugin.map 'rss watch :handle [in :chan]', + :action => 'watch_rss', + :defaults => {:url => nil, :type => nil} plugin.map 'rss watch :handle :url :type [in :chan]', :action => 'watch_rss', :defaults => {:url => nil, :type => nil}