Module: Coffeemaker::Bot::Irc::Connection

Includes:
Commands, EM::Deferrable, EM::Protocols::LineText2
Defined in:
lib/coffeemaker/bot/irc/connection.rb

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Commands

#join, #part, #privmsg

Instance Attribute Details

#hostObject

Returns the value of attribute host.



16
17
18
# File 'lib/coffeemaker/bot/irc/connection.rb', line 16

def host
  @host
end

#loggerObject

Returns the value of attribute logger.



16
17
18
# File 'lib/coffeemaker/bot/irc/connection.rb', line 16

def logger
  @logger
end

#nickObject

Returns the value of attribute nick.



16
17
18
# File 'lib/coffeemaker/bot/irc/connection.rb', line 16

def nick
  @nick
end

#on_connectObject

Returns the value of attribute on_connect.



16
17
18
# File 'lib/coffeemaker/bot/irc/connection.rb', line 16

def on_connect
  @on_connect
end

#on_messageObject

Returns the value of attribute on_message.



16
17
18
# File 'lib/coffeemaker/bot/irc/connection.rb', line 16

def on_message
  @on_message
end

#passObject

Returns the value of attribute pass.



16
17
18
# File 'lib/coffeemaker/bot/irc/connection.rb', line 16

def pass
  @pass
end

#portObject

Returns the value of attribute port.



16
17
18
# File 'lib/coffeemaker/bot/irc/connection.rb', line 16

def port
  @port
end

#sslObject

Returns the value of attribute ssl.



16
17
18
# File 'lib/coffeemaker/bot/irc/connection.rb', line 16

def ssl
  @ssl
end

#userObject

Returns the value of attribute user.



16
17
18
# File 'lib/coffeemaker/bot/irc/connection.rb', line 16

def user
  @user
end

Instance Method Details

#connection_completedObject



18
19
20
21
# File 'lib/coffeemaker/bot/irc/connection.rb', line 18

def connection_completed
  return complete_connection unless @ssl
  start_tls
end

#receive_line(data) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/coffeemaker/bot/irc/connection.rb', line 28

def receive_line(data)
  msg = ::Coffeemaker::Bot::Irc::Message.new(data)
  @logger.debug "received #{data}"

  case msg.command
  when :'001'
    on_connect.call if on_connect
    succeed
  when :ping
    send_command :pong
  when :privmsg, :topic, :part, :join
    on_message.call(msg) if on_message
  end
end

#ssl_handshake_completedObject



23
24
25
26
# File 'lib/coffeemaker/bot/irc/connection.rb', line 23

def ssl_handshake_completed
  @logger.info "ssl handshake completed"
  complete_connection
end

#unbindObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/coffeemaker/bot/irc/connection.rb', line 43

def unbind
  @logger.info "diconnected"

  @deferred_status = nil
  if @connected or @reconnecting
    EM.add_timer(1) do
      @logger.info "reconnecting"
      reconnect(@host, @port)
    end
    @connected    = false
    @reconnecting = true
  else
    raise Error, "unable to connect to server #{@host}:#{@port}"
  end
end