RSS plugin WIP
This commit is contained in:
parent
89d26ffcf1
commit
81321d07df
5
bot.rb
5
bot.rb
|
@ -2,6 +2,7 @@ require 'cinch'
|
||||||
require 'cinch-dicebag'
|
require 'cinch-dicebag'
|
||||||
require_relative 'plugins/link_info'
|
require_relative 'plugins/link_info'
|
||||||
require_relative 'plugins/help'
|
require_relative 'plugins/help'
|
||||||
|
require_relative 'plugins/rss'
|
||||||
|
|
||||||
def translit (text)
|
def translit (text)
|
||||||
table = {
|
table = {
|
||||||
|
@ -65,8 +66,8 @@ bot = Cinch::Bot.new do
|
||||||
configure do |c|
|
configure do |c|
|
||||||
c.server = "irc.forestnet.org"
|
c.server = "irc.forestnet.org"
|
||||||
c.port = 6667
|
c.port = 6667
|
||||||
c.channels = ["#urq", "#instead", "#qsp", "#ifrus"]
|
c.channels = ["#urq", "#ifrus"]
|
||||||
c.nick = 'XyZ'
|
c.nick = 'Попугай'
|
||||||
c.plugins.plugins = [
|
c.plugins.plugins = [
|
||||||
Cinch::Plugins::Dicebag,
|
Cinch::Plugins::Dicebag,
|
||||||
Cinch::Help,
|
Cinch::Help,
|
||||||
|
|
35
plugins/rss.rb
Normal file
35
plugins/rss.rb
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
require 'rss'
|
||||||
|
require 'yaml'
|
||||||
|
|
||||||
|
class RssEmitter
|
||||||
|
def initialize(bot)
|
||||||
|
@bot = bot
|
||||||
|
end
|
||||||
|
def start
|
||||||
|
cache = YAML.load_file('cache.yml')
|
||||||
|
while true
|
||||||
|
sleep 10
|
||||||
|
cache.each do |feed|
|
||||||
|
rss = RSS::Parser.parse(feed.url)
|
||||||
|
rss.items.each do |item|
|
||||||
|
if item.date > feed.date then
|
||||||
|
@send_link(rss, item)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
File.write('cache.yml', cache.to_yaml)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
def send_link(rss, item)
|
||||||
|
@bot.handlers.dispatch(:rss, rss.channel.title, item.link)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class Rss
|
||||||
|
include Cinch::Plugin
|
||||||
|
|
||||||
|
listen_to :rss
|
||||||
|
def listen(m, title, link)
|
||||||
|
print "#{title}: #{link}"
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue