4 # :title: RSS feed plugin for rbot
\r
6 # Author:: Stanislav Karchebny <berkus@madfire.net>
\r
7 # Author:: Ian Monroe <ian@monroe.nu>
\r
8 # Author:: Mark Kretschmann <markey@web.de>
\r
9 # Author:: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
\r
11 # Copyright:: (C) 2004 Stanislav Karchebny
\r
12 # Copyright:: (C) 2005 Ian Monroe, Mark Kretschmann
\r
13 # Copyright:: (C) 2006-2007 Giuseppe Bilotta
\r
15 # License:: MIT license
\r
19 # Add support for Slashdot namespace in RDF. The code is just an adaptation of
\r
20 # the DublinCore code.
\r
23 unless defined?(SLASH_PREFIX)
\r
24 SLASH_PREFIX = 'slash'
\r
25 SLASH_URI = "http://purl.org/rss/1.0/modules/slash/"
\r
27 RDF.install_ns(SLASH_PREFIX, SLASH_URI)
\r
29 module BaseSlashModel
\r
30 def append_features(klass)
\r
33 return if klass.instance_of?(Module)
\r
34 SlashModel::ELEMENT_NAME_INFOS.each do |name, plural_name|
\r
35 plural = plural_name || "#{name}s"
\r
36 full_name = "#{SLASH_PREFIX}_#{name}"
\r
37 full_plural_name = "#{SLASH_PREFIX}_#{plural}"
\r
38 klass_name = "Slash#{Utils.to_class_name(name)}"
\r
39 klass.install_must_call_validator(SLASH_PREFIX, SLASH_URI)
\r
40 klass.install_have_children_element(name, SLASH_URI, "*",
\r
41 full_name, full_plural_name)
\r
42 klass.module_eval(<<-EOC, *get_file_and_line_from_caller(0))
\r
43 remove_method :#{full_name}
\r
44 remove_method :#{full_name}=
\r
45 remove_method :set_#{full_name}
\r
48 @#{full_name}.first and @#{full_name}.first.value
\r
51 def #{full_name}=(new_value)
\r
52 @#{full_name}[0] = Utils.new_with_value_if_need(#{klass_name}, new_value)
\r
54 alias set_#{full_name} #{full_name}=
\r
62 extend BaseSlashModel
\r
65 "department" => nil,
\r
71 ELEMENT_NAME_INFOS = SlashModel::TEXT_ELEMENTS.to_a
\r
73 ELEMENTS = TEXT_ELEMENTS.keys
\r
75 ELEMENTS.each do |name, plural_name|
\r
76 module_eval(<<-EOC, *get_file_and_line_from_caller(0))
\r
77 class Slash#{Utils.to_class_name(name)} < Element
\r
92 @tag_name = #{name.dump}
\r
94 alias_method(:value, :content)
\r
95 alias_method(:value=, :content=)
\r
97 def initialize(*args)
\r
98 if Utils.element_initialize_arguments?(args)
\r
102 self.content = args[0]
\r
107 tag_name_with_prefix(SLASH_PREFIX)
\r
110 def maker_target(target)
\r
114 def setup_maker_attributes(#{name})
\r
115 #{name}.content = content
\r
123 class Item; include SlashModel; end
\r
126 SlashModel::ELEMENTS.each do |name|
\r
127 class_name = Utils.to_class_name(name)
\r
128 BaseListener.install_class_name(SLASH_URI, name, "Slash#{class_name}")
\r
131 SlashModel::ELEMENTS.collect! {|name| "#{SLASH_PREFIX}_#{name}"}
\r
138 attr_accessor :handle
\r
139 attr_accessor :type
\r
141 attr_accessor :refresh_rate
\r
143 attr_accessor :title
\r
144 attr_accessor :items
\r
145 attr_accessor :mutex
\r
147 def initialize(url,handle=nil,type=nil,watchers=[], xml=nil)
\r
156 @refresh_rate = nil
\r
161 sanitize_watchers(watchers)
\r
165 @mutex.synchronize do
\r
166 self.class.new(@url,
\r
168 @type ? @type.dup : nil,
\r
170 @xml ? @xml.dup : nil)
\r
174 # Downcase all watchers, possibly turning them into Strings if they weren't
\r
175 def sanitize_watchers(list=@watchers)
\r
187 def watched_by?(who)
\r
188 @watchers.include?(who.downcase)
\r
192 if watched_by?(who)
\r
195 @mutex.synchronize do
\r
196 @watchers << who.downcase
\r
202 @mutex.synchronize do
\r
203 @watchers.delete(who.downcase)
\r
208 [@handle,@url,@type,@refresh_rate,@watchers]
\r
211 def to_s(watchers=false)
\r
213 a = self.to_a.flatten
\r
217 a.compact.join(" | ")
\r
221 class RSSFeedsPlugin < Plugin
\r
222 BotConfig.register BotConfigIntegerValue.new('rss.head_max',
\r
223 :default => 30, :validate => Proc.new{|v| v > 0 && v < 200},
\r
224 :desc => "How many characters to use of a RSS item header")
\r
226 BotConfig.register BotConfigIntegerValue.new('rss.text_max',
\r
227 :default => 90, :validate => Proc.new{|v| v > 0 && v < 400},
\r
228 :desc => "How many characters to use of a RSS item text")
\r
230 BotConfig.register BotConfigIntegerValue.new('rss.thread_sleep',
\r
231 :default => 300, :validate => Proc.new{|v| v > 30},
\r
232 :desc => "How many seconds to sleep before checking RSS feeds again")
\r
234 # We used to save the Mutex with the RssBlob, which was idiotic. And
\r
235 # since Mutexes dumped in one version might not be resotrable in another,
\r
236 # we need a few tricks to be able to restore data from other versions of Ruby
\r
238 # When migrating 1.8.6 => 1.8.5, all we need to do is define an empty
\r
239 # #marshal_load() method for Mutex. For 1.8.5 => 1.8.6 we need something
\r
240 # dirtier, as seen later on in the initialization code.
\r
241 unless Mutex.new.respond_to?(:marshal_load)
\r
243 def marshal_load(str)
\r
251 if @registry.has_key?(:feeds)
\r
252 # When migrating from Ruby 1.8.5 to 1.8.6, dumped Mutexes may render the
\r
253 # data unrestorable. If this happens, we patch the data, thus allowing
\r
254 # the restore to work.
\r
256 # This is actually pretty safe for a number of reasons:
\r
257 # * the code is only called if standard marshalling fails
\r
258 # * the string we look for is quite unlikely to appear randomly
\r
259 # * if the string appears somewhere and the patched string isn't recoverable
\r
260 # either, we'll get another (unrecoverable) error, which makes the rss
\r
261 # plugin unsable, just like it was if no recovery was attempted
\r
262 # * if the string appears somewhere and the patched string is recoverable,
\r
263 # we may get a b0rked feed, which is eventually overwritten by a clean
\r
264 # one, so the worst thing that can happen is that a feed update spams
\r
265 # the watchers once
\r
266 @registry.recovery = Proc.new { |val|
\r
267 patched = val.sub(":\v@mutexo:\nMutex", ":\v@mutexo:\vObject")
\r
268 ret = Marshal.restore(patched)
\r
269 ret.each_value { |blob|
\r
275 @feeds = @registry[:feeds]
\r
277 @registry.recovery = nil
\r
279 @feeds.keys.grep(/[A-Z]/) { |k|
\r
280 @feeds[k.downcase] = @feeds[k]
\r
283 @feeds.each { |k, f|
\r
284 f.mutex = Mutex.new unless f.mutex
\r
285 f.sanitize_watchers
\r
286 parseRss(f) if f.xml
\r
300 @feeds.select { |h, f| f.watched? }
\r
308 unparsed = Hash.new()
\r
309 @feeds.each { |k, f|
\r
310 unparsed[k] = f.dup
\r
311 # we don't want to save the mutex
\r
312 unparsed[k].mutex = nil
\r
314 @registry[:feeds] = unparsed
\r
317 def stop_watch(handle)
\r
318 if @watch.has_key?(handle)
\r
320 debug "Stopping watch #{handle}"
\r
321 @bot.timer.remove(@watch[handle])
\r
322 @watch.delete(handle)
\r
324 report_problem("Failed to stop watch for #{handle}", e, nil)
\r
330 @watch.each_key { |k|
\r
335 def help(plugin,topic="")
\r
338 "rss show #{Bold}handle#{Bold} [#{Bold}limit#{Bold}] : show #{Bold}limit#{Bold} (default: 5, max: 15) entries from rss #{Bold}handle#{Bold}; #{Bold}limit#{Bold} can also be in the form a..b, to display a specific range of items"
\r
340 "rss list [#{Bold}handle#{Bold}] : list all rss feeds (matching #{Bold}handle#{Bold})"
\r
342 "rss watched [#{Bold}handle#{Bold}] [in #{Bold}chan#{Bold}]: list all watched rss feeds (matching #{Bold}handle#{Bold}) (in channel #{Bold}chan#{Bold})"
\r
343 when "who", "watches", "who watches"
\r
344 "rss who watches [#{Bold}handle#{Bold}]]: list all watchers for rss feeds (matching #{Bold}handle#{Bold})"
\r
346 "rss add #{Bold}handle#{Bold} #{Bold}url#{Bold} [#{Bold}type#{Bold}] : add a new rss called #{Bold}handle#{Bold} from url #{Bold}url#{Bold} (of type #{Bold}type#{Bold})"
\r
348 "rss change #{Bold}what#{Bold} of #{Bold}handle#{Bold} to #{Bold}new#{Bold} : change the #{Underline}handle#{Underline}, #{Underline}url#{Underline}, #{Underline}type#{Underline} or #{Underline}refresh#{Underline} rate of rss called #{Bold}handle#{Bold} to value #{Bold}new#{Bold}"
\r
349 when /^(del(ete)?|rm)$/
\r
350 "rss del(ete)|rm #{Bold}handle#{Bold} : delete rss feed #{Bold}handle#{Bold}"
\r
352 "rss replace #{Bold}handle#{Bold} #{Bold}url#{Bold} [#{Bold}type#{Bold}] : try to replace the url of rss called #{Bold}handle#{Bold} with #{Bold}url#{Bold} (of type #{Bold}type#{Bold}); only works if nobody else is watching it"
\r
353 when "forcereplace"
\r
354 "rss forcereplace #{Bold}handle#{Bold} #{Bold}url#{Bold} [#{Bold}type#{Bold}] : replace the url of rss called #{Bold}handle#{Bold} with #{Bold}url#{Bold} (of type #{Bold}type#{Bold})"
\r
356 "rss watch #{Bold}handle#{Bold} [#{Bold}url#{Bold} [#{Bold}type#{Bold}]] [in #{Bold}chan#{Bold}]: watch rss #{Bold}handle#{Bold} for changes (in channel #{Bold}chan#{Bold}); when the other parameters are present, the feed will be created if it doesn't exist yet"
\r
357 when /(un|rm)watch/
\r
358 "rss unwatch|rmwatch #{Bold}handle#{Bold} [in #{Bold}chan#{Bold}]: stop watching rss #{Bold}handle#{Bold} (in channel #{Bold}chan#{Bold}) for changes"
\r
360 "rss rewatch : restart threads that watch for changes in watched rss"
\r
362 "manage RSS feeds: rss show|list|watched|add|change|del(ete)|rm|(force)replace|watch|unwatch|rmwatch|rewatch"
\r
366 def report_problem(report, e=nil, m=nil)
\r
367 if m && m.respond_to?(:reply)
\r
374 debug e.backtrace.join("\n") if e.respond_to?(:backtrace)
\r
378 def show_rss(m, params)
\r
379 handle = params[:handle]
\r
380 lims = params[:limit].to_s.match(/(\d+)(?:..(\d+))?/)
\r
381 debug lims.to_a.inspect
\r
383 ll = [[lims[1].to_i-1,lims[2].to_i-1].min, 0].max
\r
384 ul = [[lims[1].to_i-1,lims[2].to_i-1].max, 14].min
\r
385 rev = lims[1].to_i > lims[2].to_i
\r
388 ul = [[lims[1].to_i-1, 0].max, 14].min
\r
392 feed = @feeds.fetch(handle.downcase, nil)
\r
394 m.reply "I don't know any feeds named #{handle}"
\r
398 m.reply "lemme fetch it..."
\r
399 title = items = nil
\r
400 fetched = fetchRss(feed, m, false)
\r
401 return unless fetched or feed.xml
\r
402 if not fetched and feed.items
\r
403 m.reply "using old data"
\r
405 parsed = parseRss(feed, m)
\r
406 m.reply "using old data" unless parsed
\r
408 return unless feed.items
\r
412 # We sort the feeds in freshness order (newer ones first)
\r
413 items = freshness_sort(items)
\r
414 disp = items[ll..ul]
\r
415 disp.reverse! if rev
\r
417 m.reply "Channel : #{title}"
\r
418 disp.each do |item|
\r
419 printFormattedRss(feed, item, {:places=>[m.replyto],:handle=>nil,:date=>true})
\r
423 def itemDate(item,ex=nil)
\r
424 return item.pubDate if item.respond_to?(:pubDate) and item.pubDate
\r
425 return item.date if item.respond_to?(:date) and item.date
\r
429 def freshness_sort(items)
\r
430 notime = Time.at(0)
\r
431 items.sort { |a, b|
\r
432 itemDate(b, notime) <=> itemDate(a, notime)
\r
436 def list_rss(m, params)
\r
437 wanted = params[:handle]
\r
439 @feeds.each { |handle, feed|
\r
440 next if wanted and !handle.match(/#{wanted}/i)
\r
441 reply << "#{feed.handle}: #{feed.url} (in format: #{feed.type ? feed.type : 'default'})"
\r
442 (reply << " refreshing every #{Utils.secs_to_string(feed.refresh_rate)}") if feed.refresh_rate
\r
443 (reply << " (watched)") if feed.watched_by?(m.replyto)
\r
447 reply = "no feeds found"
\r
448 reply << " matching #{wanted}" if wanted
\r
453 def watched_rss(m, params)
\r
454 wanted = params[:handle]
\r
455 chan = params[:chan] || m.replyto
\r
457 watchlist.each { |handle, feed|
\r
458 next if wanted and !handle.match(/#{wanted}/i)
\r
459 next unless feed.watched_by?(chan)
\r
460 reply << "#{feed.handle}: #{feed.url} (in format: #{feed.type ? feed.type : 'default'})"
\r
461 (reply << " refreshing every #{Utils.secs_to_string(feed.refresh_rate)}") if feed.refresh_rate
\r
465 reply = "no watched feeds"
\r
466 reply << " matching #{wanted}" if wanted
\r
471 def who_watches(m, params)
\r
472 wanted = params[:handle]
\r
474 watchlist.each { |handle, feed|
\r
475 next if wanted and !handle.match(/#{wanted}/i)
\r
476 reply << "#{feed.handle}: #{feed.url} (in format: #{feed.type ? feed.type : 'default'})"
\r
477 (reply << " refreshing every #{Utils.secs_to_string(feed.refresh_rate)}") if feed.refresh_rate
\r
478 reply << ": watched by #{feed.watchers.join(', ')}"
\r
482 reply = "no watched feeds"
\r
483 reply << " matching #{wanted}" if wanted
\r
488 def add_rss(m, params, force=false)
\r
489 handle = params[:handle]
\r
491 unless url.match(/https?/)
\r
492 m.reply "I only deal with feeds from HTTP sources, so I can't use #{url} (maybe you forgot the handle?)"
\r
495 type = params[:type]
\r
496 if @feeds.fetch(handle.downcase, nil) && !force
\r
497 m.reply "There is already a feed named #{handle} (URL: #{@feeds[handle.downcase].url})"
\r
501 m.reply "You must specify both a handle and an url to add an RSS feed"
\r
504 @feeds[handle.downcase] = RssBlob.new(url,handle,type)
\r
505 reply = "Added RSS #{url} named #{handle}"
\r
507 reply << " (format: #{type})"
\r
513 def change_rss(m, params)
\r
514 handle = params[:handle].downcase
\r
515 feed = @feeds.fetch(handle, nil)
\r
517 m.reply "No such feed with handle #{handle}"
\r
520 case params[:what].intern
\r
522 new = params[:new].downcase
\r
523 if @feeds.key?(new) and @feeds[new]
\r
524 m.reply "There already is a feed with handle #{new}"
\r
527 feed.mutex.synchronize do
\r
529 @feeds.delete(handle)
\r
536 feed.mutex.synchronize do
\r
539 when :format, :type
\r
541 new = nil if new == 'default'
\r
542 feed.mutex.synchronize do
\r
546 new = params[:new].to_i
\r
547 new = nil if new == 0
\r
548 feed.mutex.synchronize do
\r
549 feed.refresh_rate = new
\r
552 m.reply "Don't know how to change #{params[:what]} for feeds"
\r
555 m.reply "Feed changed:"
\r
556 list_rss(m, {:handle => handle})
\r
559 def del_rss(m, params, pass=false)
\r
560 feed = unwatch_rss(m, params, true)
\r
562 m.reply "someone else is watching #{feed.handle}, I won't remove it from my list"
\r
565 @feeds.delete(feed.handle.downcase)
\r
570 def replace_rss(m, params)
\r
571 handle = params[:handle]
\r
572 if @feeds.key?(handle.downcase)
\r
573 del_rss(m, {:handle => handle}, true)
\r
575 if @feeds.key?(handle.downcase)
\r
576 m.reply "can't replace #{feed.handle}"
\r
578 add_rss(m, params, true)
\r
582 def forcereplace_rss(m, params)
\r
583 add_rss(m, params, true)
\r
586 def watch_rss(m, params)
\r
587 handle = params[:handle]
\r
588 chan = params[:chan] || m.replyto
\r
590 type = params[:type]
\r
594 feed = @feeds.fetch(handle.downcase, nil)
\r
596 if feed.add_watch(chan)
\r
600 m.reply "Already watching #{feed.handle} in #{chan}"
\r
603 m.reply "Couldn't watch feed #{handle} (no such feed found)"
\r
607 def unwatch_rss(m, params, pass=false)
\r
608 handle = params[:handle].downcase
\r
609 chan = params[:chan] || m.replyto
\r
610 unless @feeds.has_key?(handle)
\r
611 m.reply("dunno that feed")
\r
614 feed = @feeds[handle]
\r
615 if feed.rm_watch(chan)
\r
616 m.reply "#{chan} has been removed from the watchlist for #{feed.handle}"
\r
618 m.reply("#{chan} wasn't watching #{feed.handle}") unless pass
\r
626 def rewatch_rss(m=nil, params=nil)
\r
629 # Read watches from list.
\r
630 watchlist.each{ |handle, feed|
\r
637 def watchRss(feed, m=nil)
\r
638 if @watch.has_key?(feed.handle)
\r
639 report_problem("watcher thread for #{feed.handle} is already running", nil, m)
\r
643 status[:failures] = 0
\r
644 @watch[feed.handle] = @bot.timer.add(0, status) {
\r
645 debug "watcher for #{feed} started"
\r
646 failures = status[:failures]
\r
648 debug "fetching #{feed}"
\r
649 oldxml = feed.xml ? feed.xml.dup : nil
\r
650 unless fetchRss(feed)
\r
653 if oldxml and oldxml == feed.xml
\r
654 debug "xml for #{feed} didn't change"
\r
655 failures -= 1 if failures > 0
\r
658 debug "no previous items in feed #{feed}"
\r
660 failures -= 1 if failures > 0
\r
662 otxt = feed.items.map { |item| item.to_s }
\r
663 unless parseRss(feed)
\r
664 debug "no items in feed #{feed}"
\r
667 debug "Checking if new items are available for #{feed}"
\r
668 failures -= 1 if failures > 0
\r
669 dispItems = feed.items.reject { |item|
\r
670 otxt.include?(item.to_s)
\r
672 if dispItems.length > 0
\r
673 debug "Found #{dispItems.length} new items in #{feed}"
\r
674 # When displaying watched feeds, publish them from older to newer
\r
675 dispItems.reverse.each { |item|
\r
676 printFormattedRss(feed, item)
\r
679 debug "No new items found in #{feed}"
\r
685 rescue Exception => e
\r
686 error "Error watching #{feed}: #{e.inspect}"
\r
687 debug e.backtrace.join("\n")
\r
691 status[:failures] = failures
\r
693 feed.mutex.synchronize do
\r
694 seconds = (feed.refresh_rate || @bot.config['rss.thread_sleep']) * (failures + 1)
\r
695 seconds += seconds * (rand(100)-50)/100
\r
696 debug "watcher for #{feed} going to sleep #{seconds} seconds.."
\r
697 @bot.timer.reschedule(@watch[feed.handle], seconds)
\r
700 debug "watcher for #{feed} added"
\r
703 def printFormattedRss(feed, item, opts=nil)
\r
704 places = feed.watchers
\r
705 handle = "::#{feed.handle}:: "
\r
708 places = opts[:places] if opts.key?(:places)
\r
709 handle = opts[:handle].to_s if opts.key?(:handle)
\r
710 if opts.key?(:date) && opts[:date]
\r
711 if item.respond_to?(:pubDate)
\r
712 if item.pubDate.class <= Time
\r
713 date = item.pubDate.strftime("%Y/%m/%d %H.%M.%S")
\r
715 date = item.pubDate.to_s
\r
717 elsif item.respond_to?(:date)
\r
718 if item.date.class <= Time
\r
719 date = item.date.strftime("%Y/%m/%d %H.%M.%S")
\r
721 date = item.date.to_s
\r
730 title = "#{Bold}#{item.title.chomp.riphtml}#{Bold}" if item.title
\r
732 desc = item.description.gsub(/\s+/,' ').strip.riphtml if item.description
\r
734 link = item.link.chomp if item.link
\r
737 category = item.dc_subject rescue item.category rescue nil
\r
738 author = item.dc_creator rescue item.author rescue nil
\r
743 at = ((item.title && item.link) ? ' @ ' : '')
\r
746 abt = category ? "about #{category} " : ""
\r
747 line1 = "#{handle}#{date}#{author} blogged #{abt}at #{link}"
\r
748 line2 = "#{handle}#{title} - #{desc}"
\r
750 line1 = "#{handle}#{date}#{title}#{at}#{link}"
\r
752 line1 = "#{handle}#{date}#{title}#{at}#{link} has been edited by #{author}. #{desc}"
\r
754 line1 = "#{handle}#{date}Message #{title} sent by #{author}. #{desc}"
\r
756 line1 = "#{handle}#{date}#{title} @ #{link}"
\r
757 unless item.title =~ /^Changeset \[(\d+)\]/
\r
758 line2 = "#{handle}#{date}#{desc}"
\r
761 dept = "(from the #{item.slash_department} dept) " rescue nil
\r
762 sec = " in section #{item.slash_section}" rescue nil
\r
764 line1 = "#{handle}#{date}#{dept}#{title}#{at}#{link} (posted by #{author}#{sec})"
\r
766 line1 = "#{handle}#{date}#{title}#{at}#{link}"
\r
768 places.each { |loc|
\r
769 @bot.say loc, line1, :overlong => :truncate
\r
771 @bot.say loc, line2, :overlong => :truncate
\r
775 def fetchRss(feed, m=nil, cache=true)
\r
777 # Use 60 sec timeout, cause the default is too low
\r
778 xml = @bot.httputil.get(feed.url,
\r
779 :read_timeout => 60,
\r
780 :open_timeout => 60,
\r
782 rescue URI::InvalidURIError, URI::BadURIError => e
\r
783 report_problem("invalid rss feed #{feed.url}", e, m)
\r
786 report_problem("error getting #{feed.url}", e, m)
\r
789 debug "fetched #{feed}"
\r
791 report_problem("reading feed #{feed} failed", nil, m)
\r
794 # Ok, 0.9 feeds are not supported, maybe because
\r
795 # Netscape happily removed the DTD. So what we do is just to
\r
796 # reassign the 0.9 RDFs to 1.0, and hope it goes right.
\r
797 xml.gsub!("xmlns=\"http://my.netscape.com/rdf/simple/0.9/\"",
\r
798 "xmlns=\"http://purl.org/rss/1.0/\"")
\r
799 feed.mutex.synchronize do
\r
805 def parseRss(feed, m=nil)
\r
806 return nil unless feed.xml
\r
807 feed.mutex.synchronize do
\r
810 ## do validate parse
\r
811 rss = RSS::Parser.parse(xml)
\r
812 debug "parsed and validated #{feed}"
\r
813 rescue RSS::InvalidRSSError
\r
814 ## do non validate parse for invalid RSS 1.0
\r
816 rss = RSS::Parser.parse(xml, false)
\r
817 debug "parsed but not validated #{feed}"
\r
818 rescue RSS::Error => e
\r
819 report_problem("parsing rss stream failed, whoops =(", e, m)
\r
822 rescue RSS::Error => e
\r
823 report_problem("parsing rss stream failed, oioi", e, m)
\r
826 report_problem("processing error occured, sorry =(", e, m)
\r
831 report_problem("#{feed} does not include RSS 1.0 or 0.9x/2.0", nil, m)
\r
834 rss.output_encoding = 'UTF-8'
\r
835 rescue RSS::UnknownConvertMethod => e
\r
836 report_problem("bah! something went wrong =(", e, m)
\r
839 rss.channel.title ||= "Unknown"
\r
840 title = rss.channel.title
\r
841 rss.items.each do |item|
\r
842 item.title ||= "Unknown"
\r
848 report_problem("no items found in the feed, maybe try weed?", e, m)
\r
858 plugin = RSSFeedsPlugin.new
\r
860 plugin.map 'rss show :handle :limit',
\r
861 :action => 'show_rss',
\r
862 :requirements => {:limit => /^\d+(?:\.\.\d+)?$/},
\r
863 :defaults => {:limit => 5}
\r
864 plugin.map 'rss list :handle',
\r
865 :action => 'list_rss',
\r
866 :defaults => {:handle => nil}
\r
867 plugin.map 'rss watched :handle [in :chan]',
\r
868 :action => 'watched_rss',
\r
869 :defaults => {:handle => nil}
\r
870 plugin.map 'rss who watches :handle',
\r
871 :action => 'who_watches',
\r
872 :defaults => {:handle => nil}
\r
873 plugin.map 'rss add :handle :url :type',
\r
874 :action => 'add_rss',
\r
875 :defaults => {:type => nil}
\r
876 plugin.map 'rss change :what of :handle to :new',
\r
877 :action => 'change_rss',
\r
878 :requirements => { :what => /handle|url|format|type|refresh/ }
\r
879 plugin.map 'rss change :what for :handle to :new',
\r
880 :action => 'change_rss',
\r
881 :requirements => { :what => /handle|url|format|type|refesh/ }
\r
882 plugin.map 'rss del :handle',
\r
883 :action => 'del_rss'
\r
884 plugin.map 'rss delete :handle',
\r
885 :action => 'del_rss'
\r
886 plugin.map 'rss rm :handle',
\r
887 :action => 'del_rss'
\r
888 plugin.map 'rss replace :handle :url :type',
\r
889 :action => 'replace_rss',
\r
890 :defaults => {:type => nil}
\r
891 plugin.map 'rss forcereplace :handle :url :type',
\r
892 :action => 'forcereplace_rss',
\r
893 :defaults => {:type => nil}
\r
894 plugin.map 'rss watch :handle :url :type [in :chan]',
\r
895 :action => 'watch_rss',
\r
896 :defaults => {:url => nil, :type => nil}
\r
897 plugin.map 'rss unwatch :handle [in :chan]',
\r
898 :action => 'unwatch_rss'
\r
899 plugin.map 'rss rmwatch :handle [in :chan]',
\r
900 :action => 'unwatch_rss'
\r
901 plugin.map 'rss rewatch',
\r
902 :action => 'rewatch_rss'
\r