Class: Fluent::Plugin::IRCOutput::IRCConnection
- Inherits:
-
Cool.io::TCPSocket
- Object
- Cool.io::TCPSocket
- Fluent::Plugin::IRCOutput::IRCConnection
- Defined in:
- lib/fluent/plugin/out_irc.rb
Instance Attribute Summary collapse
-
#joined ⇒ Object
readonly
for test.
-
#log ⇒ Object
Returns the value of attribute log.
-
#nick ⇒ Object
Returns the value of attribute nick.
-
#password ⇒ Object
Returns the value of attribute password.
-
#real ⇒ Object
Returns the value of attribute real.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
-
#initialize(*args) ⇒ IRCConnection
constructor
A new instance of IRCConnection.
- #join(channel) ⇒ Object
- #joined?(channel) ⇒ Boolean
- #on_connect ⇒ Object
- #on_read(data) ⇒ Object
- #send_message(command, channel, message) ⇒ Object
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
#joined ⇒ Object (readonly)
for test
179 180 181 |
# File 'lib/fluent/plugin/out_irc.rb', line 179 def joined @joined end |
#log ⇒ Object
Returns the value of attribute log.
180 181 182 |
# File 'lib/fluent/plugin/out_irc.rb', line 180 def log @log end |
#nick ⇒ Object
Returns the value of attribute nick.
180 181 182 |
# File 'lib/fluent/plugin/out_irc.rb', line 180 def nick @nick end |
#password ⇒ Object
Returns the value of attribute password.
180 181 182 |
# File 'lib/fluent/plugin/out_irc.rb', line 180 def password @password end |
#real ⇒ Object
Returns the value of attribute real.
180 181 182 |
# File 'lib/fluent/plugin/out_irc.rb', line 180 def real @real end |
#user ⇒ Object
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.(:join) do |m| m.channels = channel write m end log.debug { "out_irc: join to #{channel}" } end |
#joined?(channel) ⇒ Boolean
235 236 237 |
# File 'lib/fluent/plugin/out_irc.rb', line 235 def joined?(channel) @joined[channel] end |
#on_connect ⇒ Object
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.(:pass) do |m| m.password = @password write m end end IRCParser.(:nick) do |m| m.nick = @nick write m end IRCParser.(: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.(: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.}\"" 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 (command, channel, ) join(channel) unless joined?(channel) IRCParser.(command) do |m| m.target = channel m.body = write m end channel # return channel for test end |