Class: Fluent::IRCOutput::IRCConnection
- Inherits:
-
Cool.io::TCPSocket
- Object
- Cool.io::TCPSocket
- Fluent::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.
215 216 217 218 |
# File 'lib/fluent/plugin/out_irc.rb', line 215 def initialize(*args) super @joined = {} end |
Instance Attribute Details
#joined ⇒ Object (readonly)
for test
212 213 214 |
# File 'lib/fluent/plugin/out_irc.rb', line 212 def joined @joined end |
#log ⇒ Object
Returns the value of attribute log.
213 214 215 |
# File 'lib/fluent/plugin/out_irc.rb', line 213 def log @log end |
#nick ⇒ Object
Returns the value of attribute nick.
213 214 215 |
# File 'lib/fluent/plugin/out_irc.rb', line 213 def nick @nick end |
#password ⇒ Object
Returns the value of attribute password.
213 214 215 |
# File 'lib/fluent/plugin/out_irc.rb', line 213 def password @password end |
#real ⇒ Object
Returns the value of attribute real.
213 214 215 |
# File 'lib/fluent/plugin/out_irc.rb', line 213 def real @real end |
#user ⇒ Object
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.(:join) do |m| m.channels = channel write m end log.debug { "out_irc: join to #{channel}" } end |
#joined?(channel) ⇒ Boolean
268 269 270 |
# File 'lib/fluent/plugin/out_irc.rb', line 268 def joined?(channel) @joined[channel] end |
#on_connect ⇒ Object
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.(: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
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.(: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
280 281 282 283 284 285 286 287 288 |
# File 'lib/fluent/plugin/out_irc.rb', line 280 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 |