Class: Fluent::IRCOutput::IRCConnection

Inherits:
Cool.io::TCPSocket
  • Object
show all
Defined in:
lib/fluent/plugin/out_irc.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ IRCConnection

Returns a new instance of IRCConnection.



215
216
217
218
# File 'lib/fluent/plugin/out_irc.rb', line 215

def initialize(*args)
  super
  @joined = {}
end

Instance Attribute Details

#joinedObject (readonly)

for test



212
213
214
# File 'lib/fluent/plugin/out_irc.rb', line 212

def joined
  @joined
end

#logObject

Returns the value of attribute log.



213
214
215
# File 'lib/fluent/plugin/out_irc.rb', line 213

def log
  @log
end

#nickObject

Returns the value of attribute nick.



213
214
215
# File 'lib/fluent/plugin/out_irc.rb', line 213

def nick
  @nick
end

#passwordObject

Returns the value of attribute password.



213
214
215
# File 'lib/fluent/plugin/out_irc.rb', line 213

def password
  @password
end

#realObject

Returns the value of attribute real.



213
214
215
# File 'lib/fluent/plugin/out_irc.rb', line 213

def real
  @real
end

#userObject

Returns the value of attribute user.



213
214
215
# File 'lib/fluent/plugin/out_irc.rb', line 213

def user
  @user
end

Instance Method Details

#join(channel) ⇒ Object



272
273
274
275
276
277
278
# File 'lib/fluent/plugin/out_irc.rb', line 272

def join(channel)
  IRCParser.message(:join) do |m|
    m.channels = channel
    write m
  end
  log.debug { "out_irc: join to #{channel}" }
end

#joined?(channel) ⇒ Boolean

Returns:

  • (Boolean)


268
269
270
# File 'lib/fluent/plugin/out_irc.rb', line 268

def joined?(channel)
  @joined[channel]
end

#on_connectObject



220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/fluent/plugin/out_irc.rb', line 220

def on_connect
  if @password
    IRCParser.message(:pass) do |m|
      m.password = @password
      write m
    end
  end
  IRCParser.message(:nick) do |m|
    m.nick   = @nick
    write m
  end
  IRCParser.message(:user) do |m|
    m.user = @user
    m.postfix = @real
    write m
  end
end

#on_read(data) ⇒ Object



238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
# File 'lib/fluent/plugin/out_irc.rb', line 238

def on_read(data)
  data.each_line do |line|
    begin
      msg = IRCParser.parse(line)
      log.debug { "out_irc: on_read :#{msg.class.to_sym}" }
      case msg.class.to_sym
      when :rpl_welcome
        log.info { "out_irc: welcome \"#{msg.nick}\" to \"#{msg.prefix}\"" }
      when :ping
        IRCParser.message(:pong) do |m|
          m.target = msg.target
          m.body = msg.body
          write m
        end
      when :join
        log.info { "out_irc: joined to #{msg.channels.join(', ')}" }
        msg.channels.each {|channel| @joined[channel] = true }
      when :err_nick_name_in_use
        log.warn "out_irc: nickname \"#{msg.error_nick}\" is already in use. use \"#{@nick}_\" instead."
        @nick = "#{@nick}_"
        on_connect
      when :error
        log.warn "out_irc: an error occured. \"#{msg.error_message}\""
      end
    rescue
      #TODO
    end
  end
end

#send_message(command, channel, message) ⇒ Object



280
281
282
283
284
285
286
287
288
# File 'lib/fluent/plugin/out_irc.rb', line 280

def send_message(command, channel, message)
  join(channel) unless joined?(channel)
  IRCParser.message(command) do |m|
    m.target = channel
    m.body = message
    write m
  end
  channel # return channel for test
end