]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/rss.rb
fortune plugin: add header
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / rss.rb
index 62ce48d9e6241f1be6c40d6641dc210f5bc5b36f..4161460947cb2f4d73786142570a4d348f94e094 100644 (file)
@@ -679,7 +679,7 @@ class RSSFeedsPlugin < Plugin
     status = Hash.new\r
     status[:failures] = 0\r
     status[:first_run] = true\r
-    @watch[feed.handle] = @bot.timer.add(0, status) {\r
+    @watch[feed.handle] = @bot.timer.add(0) {\r
       debug "watcher for #{feed} started"\r
       failures = status[:failures]\r
       first_run = status.delete(:first_run)\r
@@ -761,12 +761,16 @@ class RSSFeedsPlugin < Plugin
 \r
       status[:failures] = failures\r
 \r
+      timer = nil\r
+      seconds = @bot.config['rss.thread_sleep']\r
       feed.mutex.synchronize do\r
-        seconds = (feed.refresh_rate || @bot.config['rss.thread_sleep']) * (failures + 1)\r
-        seconds += seconds * (rand(100)-50)/100\r
-        debug "watcher for #{feed} going to sleep #{seconds} seconds.."\r
-        @bot.timer.reschedule(@watch[feed.handle], seconds)\r
+        timer = @watch[feed.handle]\r
+        seconds = feed.refresh_rate if feed.refresh_rate\r
       end\r
+      seconds *= failures + 1\r
+      seconds += seconds * (rand(100)-50)/100\r
+      debug "watcher for #{feed} going to sleep #{seconds} seconds.."\r
+      @bot.timer.reschedule(timer, seconds) rescue warning "watcher for #{feed} failed to reschedule: #{$!.inspect}"\r
     }\r
     debug "watcher for #{feed} added"\r
   end\r