class Syndi::IRC::Library

The base of the IRC framework.

@!attribute [r] events

@return [Syndi::API::Events] The IRC event system.

@!attribute [r] connections

@return [Hash{String => Syndi::IRC::Server}] Collection of IRC connections.

Attributes

connections[R]
events[R]

Public Class Methods

new() click to toggle source
# 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

Public Instance Methods

receive(socket_object) click to toggle source

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.
# 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
start() click to toggle source

Initiate IRC connections.

# 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