Class: Cinch::Plugins::Starcraft::FeedsReader

Inherits:
Object
  • Object
show all
Defined in:
lib/cinch/plugins/starcraft/feeds.rb

Instance Method Summary collapse

Constructor Details

#initialize(bot, channels) ⇒ FeedsReader

Returns a new instance of FeedsReader.



5
6
7
8
# File 'lib/cinch/plugins/starcraft/feeds.rb', line 5

def initialize(bot, channels)
  @bot, @channels = bot, channels
  @feeds = Feedzirra::Feed.fetch_and_parse( User.all.map { |u| u.feed } )
end

Instance Method Details

#startObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/cinch/plugins/starcraft/feeds.rb', line 10

def start
  loop do
    sleep $config['rss']['interval']
    begin
      @feeds = Feedzirra::Feed.update(@feeds.values)
      @feeds.each do |feed|
        feed = feed[1]
        nick = User.find_by_username( feed.title.split(" ").last ).nick
        entries = feed.new_entries[0..($config['rss']['floodlines']-1)]
        entries.each do |entry|
          msg = "#{nick} just played #{entry.title}"
          @bot.dispatch(:rss_update, nil, {:channels => @channels, :message => msg })
        end
      end
    rescue Exception => e
      puts e # Probably no feeds to refresh
    end
  end
end