Class: Fluent::Plugin::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.



182
183
184
185
# File 'lib/fluent/plugin/out_irc.rb', line 182

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

Instance Attribute Details

#joinedObject (readonly)

for test



179
180
181
# File 'lib/fluent/plugin/out_irc.rb', line 179

def joined
  @joined
end

#logObject

Returns the value of attribute log.



180
181
182
# File 'lib/fluent/plugin/out_irc.rb', line 180

def log
  @log
end

#nickObject

Returns the value of attribute nick.



180
181
182
# File 'lib/fluent/plugin/out_irc.rb', line 180

def nick
  @nick
end

#passwordObject

Returns the value of attribute password.



180
181
182
# File 'lib/fluent/plugin/out_irc.rb', line 180

def password
  @password
end

#realObject

Returns the value of attribute real.



180
181
182
# File 'lib/fluent/plugin/out_irc.rb', line 180

def real
  @real
end

#userObject

Returns the value of attribute user.



180
181
182
# File 'lib/fluent/plugin/out_irc.rb', line 180

def user
  @user
end

Instance Method Details

#join(channel) ⇒ Object



239
240
241
242
243
244
245
# File 'lib/fluent/plugin/out_irc.rb', line 239

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)


235
236
237
# File 'lib/fluent/plugin/out_irc.rb', line 235

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

#on_connectObject



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/fluent/plugin/out_irc.rb', line 187

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



205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/fluent/plugin/out_irc.rb', line 205

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



247
248
249
250
251
252
253
254
255
# File 'lib/fluent/plugin/out_irc.rb', line 247

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