]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/rss.rb
lart plugin: replace "me" with sourcenick
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / rss.rb
index 2d72312af88ba4fb8be1683e4316587d70e59857..f8d8c99795647db4672edbd791ee2675c012eb15 100644 (file)
@@ -676,13 +676,23 @@ class RSSFeedsPlugin < Plugin
   end\r
 \r
   def rewatch_rss(m=nil, params=nil)\r
-    stop_watches\r
+    if params and handle = params[:handle]\r
+      feed = @feeds.fetch(handle.downcase, nil)\r
+      if feed\r
+        @bot.timer.reschedule(@watch[feed.handle], 0)\r
+        m.okay if m\r
+      else\r
+        m.reply _("no such feed %{handle}") % { :handle => handle } if m\r
+      end\r
+    else\r
+      stop_watches\r
 \r
-    # Read watches from list.\r
-    watchlist.each{ |handle, feed|\r
-      watchRss(feed, m)\r
-    }\r
-    m.okay if m\r
+      # Read watches from list.\r
+      watchlist.each{ |handle, feed|\r
+        watchRss(feed, m)\r
+      }\r
+      m.okay if m\r
+    end\r
   end\r
 \r
   private\r
@@ -802,6 +812,12 @@ class RSSFeedsPlugin < Plugin
       return seconds\r
   end\r
 \r
+  def select_nonempty(*ar)\r
+    debug ar\r
+    ret = ar.map { |i| (i && i.empty?) ? nil : i }.compact.first\r
+    (ret && ret.empty?) ? nil : ret\r
+  end\r
+\r
   def printFormattedRss(feed, item, opts=nil)\r
     debug item\r
     places = feed.watchers\r
@@ -847,7 +863,14 @@ class RSSFeedsPlugin < Plugin
     # limit to 160 characters, and most of them are under 140 characters\r
     tit_opt[:limit] = @bot.config['rss.head_max'] unless feed.type == 'twitter'\r
 \r
-    title = "#{Bold}#{item.title.to_s.ircify_html(tit_opt)}#{Bold}" if item.title\r
+    if item.title\r
+      base_title = item.title.to_s.dup\r
+      # git changesets are SHA1 hashes (40 hex digits), way too long, get rid of them, as they are\r
+      # visible in the URL anyway\r
+      # TODO make this optional?\r
+      base_title.sub!(/^Changeset \[([\da-f]{40})\]:/) { |c| "(git commit)"} if feed.type = 'trac'\r
+      title = "#{Bold}#{base_title.ircify_html(tit_opt)}#{Bold}"\r
+    end\r
 \r
     desc_opt = {\r
       :limit => @bot.config['rss.text_max'],\r
@@ -869,10 +892,8 @@ class RSSFeedsPlugin < Plugin
 \r
     link = item.link.href rescue item.link.chomp rescue nil\r
 \r
-    category = item.category.content rescue item.dc_subject rescue nil\r
-    category = nil if category and category.empty?\r
-    author = item.author.name.content rescue item.dc_creator rescue item.author rescue nil\r
-    author = nil if author and author.empty?\r
+    category = select_nonempty((item.category.content rescue nil), (idem.dc_subject rescue nil))\r
+    author = select_nonempty((item.author.name.content rescue nil), (item.dc_creator rescue nil), (item.author rescue nil))\r
 \r
     line1 = nil\r
     line2 = nil\r
@@ -881,10 +902,13 @@ class RSSFeedsPlugin < Plugin
 \r
     case feed.type\r
     when 'blog'\r
-      author << " " if author\r
+      author += " " if author\r
       abt = category ? "about #{category} " : ""\r
       line1 = "#{handle}#{date}#{author}blogged #{abt}at #{link}"\r
       line2 = "#{handle}#{title} - #{desc}"\r
+    when 'git'\r
+      author += " " if author\r
+      line1 = "#{handle}#{date}#{author}commited #{title} @ #{link}"\r
     when 'forum'\r
       line1 = "#{handle}#{date}#{title}#{at}#{link}"\r
     when 'wiki'\r
@@ -893,7 +917,7 @@ class RSSFeedsPlugin < Plugin
       line1 = "#{handle}#{date}Message #{title} sent by #{author}. #{desc}"\r
     when 'trac'\r
       line1 = "#{handle}#{date}#{title} @ #{link}"\r
-      unless item.title =~ /^Changeset \[(\d+)\]/\r
+      unless item.title =~ /^(?:Changeset \[(?:[\da-f]+)\]|\(git commit\))/\r
         line2 = "#{handle}#{date}#{desc}"\r
       end\r
     when '/.'\r
@@ -1057,5 +1081,5 @@ plugin.map 'rss unwatch :handle [in :chan]',
   :action => 'unwatch_rss'\r
 plugin.map 'rss rmwatch :handle [in :chan]',\r
   :action => 'unwatch_rss'\r
-plugin.map 'rss rewatch',\r
+plugin.map 'rss rewatch [:handle]',\r
   :action => 'rewatch_rss'\r