Sha256: 94d38dfd8bc1f977dd0eb646f2dbeb5ddc12b272c05d627e9dda94c2374c8672
Contents?: true
Size: 1.63 KB
Versions: 6
Compression:
Stored size: 1.63 KB
Contents
require 'open-uri' require 'rss' module Cinch module Plugins class Rss include Cinch::Plugin set :plugin_name, 'rss' set :help, <<EOT The RSS plugin will poll rss feed every options['cogconf']['rss']['polling'] minutes EOT def initialize(bot) super @bot = bot @feeds = {} timer = Timer @bot.config.options['cogconf']['rss']['polling'], method: :fetch_rss timers << timer end def fetch_rss @bot.debug 'Fetching rss' @feeds ||= {} @bot.config.options['cogconf']['rss']['channels'].each do |chan| prefix = chan['prefix'] open(chan['url']) do |rss| feed = RSS::Parser.parse(rss) @feeds[prefix] ||= [] feed.items.reverse.each do |item| unless @feeds[prefix].include? item.title @feeds[prefix] << item.title # to prevent the first run displays all the items if @feeds[prefix].length > feed.items.length chan['announce'].each do |announce| msg = "#{prefix} #{item.title} (#{item.link})" if chan['transform'] msg.gsub! Regexp.new(chan['transform']['regexp']), chan['transform']['replace'] end Channel(announce).send msg end end end end if @feeds[prefix].length > (feed.items.length * 3) @feeds[prefix] = @feeds[prefix][-(feed.items.length * 3), (feed.items.length * 3)] end end end end end end end
Version data entries
6 entries across 6 versions & 1 rubygems
Version | Path |
---|---|
cogbot-0.1.14 | plugins/rss.rb |
cogbot-0.1.13 | plugins/rss.rb |
cogbot-0.1.12 | plugins/rss.rb |
cogbot-0.1.11 | plugins/rss.rb |
cogbot-0.1.10 | plugins/rss.rb |
cogbot-0.1.9 | plugins/rss.rb |