Class: Reddit
Instance Attribute Summary collapse
Instance Method Summary
collapse
#create_database, #match, #on_channel, #on_join
Constructor Details
#initialize(bot) ⇒ Reddit
9
10
11
12
|
# File 'lib/muzang-plugins/muzang-reddit.rb', line 9
def initialize(bot)
@bot = bot
create_database("last_update.yml", Time.now, :last_update)
end
|
Instance Attribute Details
#last_update ⇒ Object
Returns the value of attribute last_update.
7
8
9
|
# File 'lib/muzang-plugins/muzang-reddit.rb', line 7
def last_update
@last_update
end
|
Instance Method Details
#call(connection, message) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/muzang-plugins/muzang-reddit.rb', line 14
def call(connection, message)
on_join(connection, message) do
EventMachine::add_periodic_timer(period) do
http = EventMachine::HttpRequest.new('http://www.reddit.com/r/ruby/.rss').get
http.callback {
= ::Parser.parse(http.response, false)
.items.each do |item|
connection.msg(message.channel, "#{item.title} | #{item.link}") if item.date > @last_update
end
save()
}
end
end
end
|
#period ⇒ Object
35
36
37
|
# File 'lib/muzang-plugins/muzang-reddit.rb', line 35
def period
30
end
|
#save(rss) ⇒ Object
30
31
32
33
|
# File 'lib/muzang-plugins/muzang-reddit.rb', line 30
def save()
@last_update = .items.max_by{|i|i.date}.date
file = File.open(@config + "/last_update.yml", "w"){|f| f.write YAML::dump(@last_update)}
end
|