Class: Cerberus::Publisher::IRC

Inherits:
Base
  • Object
show all
Defined in:
lib/cerberus/publisher/irc.rb

Class Method Summary collapse

Methods inherited from Base

formatted_message

Class Method Details

.publish(state, manager, options) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/cerberus/publisher/irc.rb', line 6

def self.publish(state, manager, options)
  irc_options = options[:publisher, :irc]
  raise "There is no channel provided for IRC publisher" unless irc_options[:channel]
  subject,body = Cerberus::Publisher::Base.formatted_message(state, manager, options)
  message = subject + "\n" + '*' * subject.length + "\n" + body

  channel = '#' + irc_options[:channel]
  bot = IRC.new(irc_options[:nick] || 'cerberus', irc_options[:server], irc_options[:port] || 6667)

  silence_stream(STDOUT) do
    IRCEvent.add_callback('endofmotd') do |event| 
      bot.add_channel(channel) 
      message.split("\n").each do |line|
        bot.send_message(channel, line)
      end
      bot.send_quit
    end
    bot.connect
  end

end