Commit 371848f0 authored by Cool Fire's avatar Cool Fire
Browse files

Added plugin for ubuntu security rss feed

parent 5c0ba444
Pipeline #48 passed with stage
in 15 seconds
#!/usr/bin/env ruby
# Plugin that monitors the Ubuntu security announcements
class Ubuntusecurity
require 'mechanize'
require 'nokogiri'
def initialize( status, config, output, irc, timer )
@status = status
@config = config
@output = output
@irc = irc
@timer = timer
@feed_url = 'http://www.ubuntu.com/usn/rss.xml'
@feed_last = ''
@feed_timer = 600
@channel = '#news'
if( @status.threads && @config.threads)
@rss_thread = Thread.new{ check_rss }
end
end
# Default action for this plugin
def main( nick, user, host, from, msg, arguments, con )
end
# Method to be called when the plugin is unloaded
def unload
if( @status.threads && @config.threads)
@rss_thread.exit
end
return true
end
private
def check_rss
while true
begin
agent = Mechanize.new
# Grab rss
xml = agent.get( @feed_url ).body
xml = Nokogiri::XML( xml )
# Parse out info
title, link = "", ""
title = xml.css( 'item title' ).first.text
link = xml.css( 'item link' ).first.text
if(link != @feed_last)
@feed_last = link
# If the tinyurl plugin is loaded, use it
if( @status.checkplugin( "tinyurl" ) )
plugin = @status.getplugin( "tinyurl" )
link = plugin.main( nil, nil, nil, nil, nil, link, false )
end
@irc.message( @channel, "\x02\x037,1Ubuntu\x0f #{title} | #{link}" )
@irc.message( @channel, " " )
end
rescue Exception => e
# Silently fail
@output.debug( "Failure while retrieving rss feed: #{e.to_s}\n" )
end
# Wait for a bit before fetching again
sleep( @feed_timer )
end
end
end
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment