Skip to content

Instantly share code, notes, and snippets.

@AgoristRadio
Created October 28, 2013 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AgoristRadio/7205521 to your computer and use it in GitHub Desktop.
Save AgoristRadio/7205521 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# encoding: utf-8
require "rubygems"
require "amqp"
require "cinch"
class RailsMonitor
def initialize(bot)
@bot = bot
EventMachine.run do
connection = AMQP.connect(:host => '127.0.0.1')
puts "Connected to AMQP broker."
channel = AMQP::Channel.new(connection)
queue = channel.queue("amqpgem.rails.monitor", :durable => true)
exchange = channel.direct("")
queue.subscribe do |payload|
self.msg("#{payload}")
end
end
end
def msg(msg)
@bot.handlers.dispatch(:monitor_msg, nil, msg)
end
end
class JoinPart
include Cinch::Plugin
match /join (.+)/, method: :join
match /part(?: (.+))?/, method: :part
def initialize(*args)
super
@admins = ["admin_username"]
end
def check_user(user)
user.refresh
@admins.include?(user.authname)
end
def join(m, channel)
return unless check_user(m.user)
Channel(channel).join
end
def part(m, channel)
return unless check_user(m.user)
channel ||= m.channel
Channel(channel).part if channel
end
end
class MonitorBot
include Cinch::Plugin
listen_to :monitor_msg
def listen(m, msg)
if msg.include? "[WARN]"
Channel("#myawesomechannel").send Format(:red,"#{msg}")
elsif msg.include? "[INFO]"
Channel("#myawesomechannel").send Format(:green,"#{msg}")
else
Channel("#myawesomechannel").send "#{msg}"
end
end
end
bot = Cinch::Bot.new do
configure do |c|
c.nick = "railsmonitor"
c.realname = "railsmonitor"
c.user = "railsmonitor"
c.server = "irc.freenode.org"
#c.port = 7000
#c.ssl = true
c.channels = []
c.verbose = true
c.plugins.plugins = [MonitorBot,JoinPart]
end
end
Thread.new { RailsMonitor.new(bot).start }
bot.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment