Class: Syndi::IRC::Library

Inherits:
Object
  • Object
show all
Defined in:
lib/syndi/irc/library.rb

Overview

The base of the IRC framework.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLibrary

Returns a new instance of Library.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/syndi/irc/library.rb', line 26

def initialize

  # Initialize our event system.
  @events      = Syndi::API::Events.new
  # Prepare our collection of IRC server connections.
  @connections = Hash.new

  # Be ready to accept data.
  $m.events.on :net_receive, 1, &method(:receive)

  # Start connections when Syndi is started.
  $m.events.on :start, &method(:start)

  # Parse data.
  @parser = Syndi::IRC::Protocol.new self

  # Handle common functions.
  @common = Syndi::IRC::Common.new self
  
end

Instance Attribute Details

#connectionsHash{String => Syndi::IRC::Server} (readonly)

Returns Collection of IRC connections.

Returns:



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/syndi/irc/library.rb', line 22

class Library

  attr_reader :events, :connections

  def initialize

    # Initialize our event system.
    @events      = Syndi::API::Events.new
    # Prepare our collection of IRC server connections.
    @connections = Hash.new
  
    # Be ready to accept data.
    $m.events.on :net_receive, 1, &method(:receive)

    # Start connections when Syndi is started.
    $m.events.on :start, &method(:start)

    # Parse data.
    @parser = Syndi::IRC::Protocol.new self

    # Handle common functions.
    @common = Syndi::IRC::Common.new self
    
  end # def initialize

  # Process incoming network data.
  #
  # @param [Object] socket_object The socket object, which in the case of
  #   ourselves should be an {Syndi::IRC::Server}, or we won't handle it.
  def receive socket_object
    if socket_object.instance_of? Syndi::IRC::Server
      socket_object.recv
    end
  end

  # Initiate IRC connections.
  def start
    
    # Iterate through each IRC server in the config, and connect to it.
    $m.conf['irc'].each do |name, hash|
      begin
        # Configure the IRC instance.
        @connections[name] = Syndi::IRC::Server.new(name) do |c|
          c.address = hash['address']
          c.port    = hash['port']
          c.nick    = hash['nickname'][0] 
          c.user    = hash['username']
          c.real    = hash['realName']
          c.ssl     = hash['useSSL']
        end

        # Connect.
        $m.sockets << @connections[name]
        @connections[name].connect
      rescue => e
        $m.error("Connection to #{name} failed: #{e}", false, e.backtrace)
      end
    end

  end # def start

end

#eventsSyndi::API::Events (readonly)

Returns The IRC event system.

Returns:

  • (Syndi::API::Events)

    The IRC event system.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/syndi/irc/library.rb', line 22

class Library

  attr_reader :events, :connections

  def initialize

    # Initialize our event system.
    @events      = Syndi::API::Events.new
    # Prepare our collection of IRC server connections.
    @connections = Hash.new
  
    # Be ready to accept data.
    $m.events.on :net_receive, 1, &method(:receive)

    # Start connections when Syndi is started.
    $m.events.on :start, &method(:start)

    # Parse data.
    @parser = Syndi::IRC::Protocol.new self

    # Handle common functions.
    @common = Syndi::IRC::Common.new self
    
  end # def initialize

  # Process incoming network data.
  #
  # @param [Object] socket_object The socket object, which in the case of
  #   ourselves should be an {Syndi::IRC::Server}, or we won't handle it.
  def receive socket_object
    if socket_object.instance_of? Syndi::IRC::Server
      socket_object.recv
    end
  end

  # Initiate IRC connections.
  def start
    
    # Iterate through each IRC server in the config, and connect to it.
    $m.conf['irc'].each do |name, hash|
      begin
        # Configure the IRC instance.
        @connections[name] = Syndi::IRC::Server.new(name) do |c|
          c.address = hash['address']
          c.port    = hash['port']
          c.nick    = hash['nickname'][0] 
          c.user    = hash['username']
          c.real    = hash['realName']
          c.ssl     = hash['useSSL']
        end

        # Connect.
        $m.sockets << @connections[name]
        @connections[name].connect
      rescue => e
        $m.error("Connection to #{name} failed: #{e}", false, e.backtrace)
      end
    end

  end # def start

end

Instance Method Details

#receive(socket_object) ⇒ Object

Process incoming network data.

Parameters:

  • socket_object (Object)

    The socket object, which in the case of ourselves should be an Server, or we won't handle it.



51
52
53
54
55
# File 'lib/syndi/irc/library.rb', line 51

def receive socket_object
  if socket_object.instance_of? Syndi::IRC::Server
    socket_object.recv
  end
end

#startObject

Initiate IRC connections.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/syndi/irc/library.rb', line 58

def start
  
  # Iterate through each IRC server in the config, and connect to it.
  $m.conf['irc'].each do |name, hash|
    begin
      # Configure the IRC instance.
      @connections[name] = Syndi::IRC::Server.new(name) do |c|
        c.address = hash['address']
        c.port    = hash['port']
        c.nick    = hash['nickname'][0] 
        c.user    = hash['username']
        c.real    = hash['realName']
        c.ssl     = hash['useSSL']
      end

      # Connect.
      $m.sockets << @connections[name]
      @connections[name].connect
    rescue => e
      $m.error("Connection to #{name} failed: #{e}", false, e.backtrace)
    end
  end

end