Class: Net::IRC::Client

### Home Classes Methods

### In Files

- lib/net/irc/client.rb

### Parent

Object

### Namespace

- MODULE Net::IRC::Client::ChannelManager

### Methods

- ::new
- #finish
- #method_missing
- #on_connected
- #on_disconnected
- #on_message
- #on_ping
- #on_rpl_isupport
- #on_rpl_welcome
- #start

### Included Modules

- Net::IRC

### Files

- README

### Class/Module Index

Quicksearch

- Net
- Net::IRC
- Net::IRC::Client
- Net::IRC::Client::ChannelManager
- Net::IRC::IRCException
- Net::IRC::Message
- Net::IRC::Message::InvalidMessage
- Net::IRC::Message::ModeParser
- Net::IRC::Message::ServerConfig
- Net::IRC::Prefix
- Net::IRC::Server
- Net::IRC::Server::Session
- Object

No matching classes.

# Net::IRC::Client

### Public Class Methods

new(host, port, opts={}) click to toggle source

    # File lib/net/irc/client.rb, line 8
            def initialize(host, port, opts={})
                    @host          = host
                    @port          = port
                    @opts          = OpenStruct.new(opts)
                    @log           = @opts.logger || Logger.new($stdout)
                    @server_config = Message::ServerConfig.new
                    @channels = {
    #                       "#channel" => {
    #                               :modes => [],
    #                               :users => [],
    #                       }
                    }
                    @channels.extend(MonitorMixin)
            end

### Public Instance Methods

finish() click to toggle source

Close connection to server.

    # File lib/net/irc/client.rb, line 53
    def finish
            begin
                    @socket.close
            rescue
            end
            on_disconnected
    end

method_missing(name, *args) click to toggle source

Do nothing. This is for avoiding error on calling super. So you can always call super at subclass.

    # File lib/net/irc/client.rb, line 86
    def method_missing(name, *args)
    end

on_connected() click to toggle source

Call when socket connected.

    # File lib/net/irc/client.rb, line 90
    def on_connected
    end

on_disconnected() click to toggle source

Call when socket closed.

    # File lib/net/irc/client.rb, line 94
    def on_disconnected
    end

on_message(m) click to toggle source

Catch all messages. If this method return true, aother callback will not be called.

    # File lib/net/irc/client.rb, line 63
    def on_message(m)
    end

on_ping(m) click to toggle source

Default PING callback. Response PONG.

    # File lib/net/irc/client.rb, line 79
    def on_ping(m)
            post PONG, @prefix ? @prefix.nick : ""
    end

on_rpl_isupport(m) click to toggle source

Default RPL_ISUPPORT callback. This detects server's configurations.

    # File lib/net/irc/client.rb, line 74
    def on_rpl_isupport(m)
            @server_config.set(m)
    end

on_rpl_welcome(m) click to toggle source

Default RPL_WELCOME callback. This sets @prefix from the message.

    # File lib/net/irc/client.rb, line 68
    def on_rpl_welcome(m)
            @prefix = Prefix.new(m[1][/\S+\z/])
    end

start() click to toggle source

Connect to server and start loop.

    # File lib/net/irc/client.rb, line 24
    def start
            # reset config
            @server_config = Message::ServerConfig.new
            @socket = TCPSocket.open(@host, @port)
            on_connected
            post PASS, @opts.pass if @opts.pass
            post NICK, @opts.nick
            post USER, @opts.user, "0", "*", @opts.real
            while l = @socket.gets
                    begin
                            @log.debug "RECEIVE: #{l.chomp}"
                            m = Message.parse(l)
                            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

[Validate]

Generated with the Darkfish Rdoc Generator 2.