Commit 0fb7ca2e authored by Cool Fire's avatar Cool Fire

Add plugin to set topic of #news to "istheinternetonfire.com" status.

parent 8b279449
Pipeline #246 passed with stages
in 14 minutes and 58 seconds
#!/usr/bin/env ruby
# Plugin that monitors istheinternetonfire.com
class Internetonfire
require 'json'
require 'open-uri'
def initialize( status, config, output, irc, timer )
@status = status
@config = config
@output = output
@irc = irc
@timer = timer
@url = 'https://istheinternetonfire.com/status.json'
@timer = 3600
@recent = ''
@channel = '#news'
@prefix = 'Tech news & security bulletins'
if( @status.threads && @config.threads)
@retr_thread = Thread.new{ check_state }
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)
@retr_thread.exit
end
return true
end
private
def check_state
loop do
begin
response = open(@url).read
state = JSON.parse(response)['status']
# Check if changed since last time
if @recent == state
raise 'No update'
else
@recent = state
# Set topic
@irc.topic( @channel, "#{@prefix} | Is the internet on fire? #{state}" )
end
rescue Exception => e
# Silently fail
@output.debug( "Error while reading status: #{e.message}\n" )
end
# Wait for a bit before fetching again
sleep( @timer )
end
end
end
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