Class: CrazyDoll::IRC

Inherits:
Net::IRC::Client
  • Object
show all
Defined in:
lib/crazy_doll/irc.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#event_managerObject

Returns the value of attribute event_manager.



3
4
5
# File 'lib/crazy_doll/irc.rb', line 3

def event_manager
  @event_manager
end

Instance Method Details

#finishObject



35
36
37
38
# File 'lib/crazy_doll/irc.rb', line 35

def finish
  super
  @event_manager.fire(:sys, :socket_stop)
end

#real_name(n, m) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/crazy_doll/irc.rb', line 40

def real_name(n,m)
  $msg = [n, m]
  o = if n == 'privmsg'
    if m[0][0].chr == '#'
      'chanmsg'
    elsif m[1] == "\x01VERSION \x01"
      'version'
    end
  end
  o.nil? ? n : o
end

#startObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/crazy_doll/irc.rb', line 5

def start
  # reset config
  @server_config = Message::ServerConfig.new
  @socket = TCPSocket.open(@host, @port)
  @event_manager.fire(:sys, :socket_start)
  while l = @socket.gets
    begin
      @log.debug "RECEIVE: #{l.chomp}"
      m = Message.parse(l)
      name = real_name((COMMANDS[m.command.upcase] || m.command).downcase, m)
      @log.debug "TYPE: get_#{name}"
      @event_manager.fire(:get, name, CrazyDoll::Message.parse(l.chomp), l.chomp)
      #next if on_message(m) === true
      #name = "on_#{(COMMANDS[m.command.upcase] || m.command).downcase}"
      #send(name, m) if respond_to?(name)
    rescue Exception => e
      warn e
      warn e.backtrace.join("\r\t")
      raise
    rescue Message::InvalidMessage
      @log.error "MessageParse: " + l.inspect
    end
  end
  rescue IOError
  ensure
    finish
end