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

Instance Attribute Details

#channelObject

Returns the value of attribute channel.



98
99
100
# File 'lib/fluent/plugin/out_irc.rb', line 98

def channel
  @channel
end

#nickObject

Returns the value of attribute nick.



98
99
100
# File 'lib/fluent/plugin/out_irc.rb', line 98

def nick
  @nick
end

#passwordObject

Returns the value of attribute password.



98
99
100
# File 'lib/fluent/plugin/out_irc.rb', line 98

def password
  @password
end

#realObject

Returns the value of attribute real.



98
99
100
# File 'lib/fluent/plugin/out_irc.rb', line 98

def real
  @real
end

#userObject

Returns the value of attribute user.



98
99
100
# File 'lib/fluent/plugin/out_irc.rb', line 98

def user
  @user
end

Instance Method Details

#on_connectObject



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/fluent/plugin/out_irc.rb', line 100

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



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/fluent/plugin/out_irc.rb', line 118

def on_read(data)
  data.each_line do |line|
    begin
      msg = IRCParser.parse(line)
      case msg.class.to_sym
      when :rpl_welcome
        IRCParser.message(:join) do |m|
          m.channels = @channel
          write m
        end
      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) ⇒ Object



143
144
145
146
147
148
149
# File 'lib/fluent/plugin/out_irc.rb', line 143

def send_message(msg)
  IRCParser.message(:priv_msg) do |m|
    m.target = @channel
    m.body = msg
    write m
  end
end