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.



155
156
157
158
# File 'lib/fluent/plugin/out_irc.rb', line 155

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

Instance Attribute Details

#channelObject

Returns the value of attribute channel.



153
154
155
# File 'lib/fluent/plugin/out_irc.rb', line 153

def channel
  @channel
end

#commandObject

Returns the value of attribute command.



153
154
155
# File 'lib/fluent/plugin/out_irc.rb', line 153

def command
  @command
end

#nickObject

Returns the value of attribute nick.



153
154
155
# File 'lib/fluent/plugin/out_irc.rb', line 153

def nick
  @nick
end

#passwordObject

Returns the value of attribute password.



153
154
155
# File 'lib/fluent/plugin/out_irc.rb', line 153

def password
  @password
end

#realObject

Returns the value of attribute real.



153
154
155
# File 'lib/fluent/plugin/out_irc.rb', line 153

def real
  @real
end

#userObject

Returns the value of attribute user.



153
154
155
# File 'lib/fluent/plugin/out_irc.rb', line 153

def user
  @user
end

Instance Method Details

#join(channel) ⇒ Object



202
203
204
205
206
207
208
# File 'lib/fluent/plugin/out_irc.rb', line 202

def join(channel)
  IRCParser.message(:join) do |m|
    m.channels = channel
    write m
  end
  @joined[channel] = true
end

#joined?(channel) ⇒ Boolean

Returns:

  • (Boolean)


198
199
200
# File 'lib/fluent/plugin/out_irc.rb', line 198

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

#on_connectObject



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/fluent/plugin/out_irc.rb', line 160

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



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/fluent/plugin/out_irc.rb', line 178

def on_read(data)
  data.each_line do |line|
    begin
      msg = IRCParser.parse(line)
      case msg.class.to_sym
      when :ping
        IRCParser.message(:pong) do |m|
          m.target = msg.target
          m.body = msg.body
          write m
        end
      when :error
        log.warn "out_irc: an error occured. \"#{msg.error_message}\""
      end
    rescue
      #TODO
    end
  end
end

#send_message(msg, channel) ⇒ Object



210
211
212
213
214
215
216
217
# File 'lib/fluent/plugin/out_irc.rb', line 210

def send_message(msg, channel)
  join(channel) unless joined?(channel)
  IRCParser.message(@command) do |m|
    m.target = channel
    m.body = msg
    write m
  end
end