Sha256: c22baef27818563838e7153ea1ede1223aff8d2fa8b8aff0a2a1a8124be6a5c8
Contents?: true
Size: 999 Bytes
Versions: 3
Compression:
Stored size: 999 Bytes
Contents
require "em-http-request" require "rss/1.0" require "rss/2.0" class Reddit include Muzang::Plugins::Helpers attr_accessor :last_update def initialize(bot) @bot = bot create_database("last_update.yml", Time.now, :last_update) end def call(connection, message) if on_join?(connection, message) EventMachine::add_periodic_timer(period) do http = EventMachine::HttpRequest.new('http://www.reddit.com/r/ruby/.rss').get http.errback { # exceptioner } http.callback { rss = RSS::Parser.parse(http.response, false) rss.items.each do |item| connection.msg(message.channel, "#{item.title} | #{item.link}") if item.date > @last_update end save(rss) } end end end def save(rss) @last_update = rss.items.max_by{|i|i.date}.date file = File.open(@config + "/last_update.yml", "w"){|f| f.write YAML::dump(@last_update)} end def period 30 end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
muzang-plugins-1.0.2 | lib/muzang-plugins/muzang-reddit.rb |
muzang-plugins-1.0.1 | lib/muzang-plugins/muzang-reddit.rb |
muzang-plugins-1.0.0 | lib/muzang-plugins/muzang-reddit.rb |