Module: Net::IRC::Client::ChannelManager

### Home Classes Methods

### In Files

- lib/net/irc/client/channel_manager.rb

### Methods

- #init_channel
- #on_join
- #on_kick
- #on_mode
- #on_nick
- #on_part
- #on_quit
- #on_rpl_namreply

### 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::ChannelManager

### Public Instance Methods

init_channel(channel) click to toggle source

For managing channel

    # File lib/net/irc/client/channel_manager.rb, line 136
    def init_channel(channel)
            @channels[channel] ||= {
                    :modes => [],
                    :users => [],
            }
    end

on_join(m) click to toggle source

For managing channel

    # File lib/net/irc/client/channel_manager.rb, line 86
    def on_join(m)
            nick    = m.prefix.nick
            channel = m[0]

            @channels.synchronize do
                    init_channel(channel)

                    @channels[channel][:users] << nick
                    @channels[channel][:users].uniq!
            end
    end

on_kick(m) click to toggle source

For managing channel

    # File lib/net/irc/client/channel_manager.rb, line 66
    def on_kick(m)
            users = m[1].split(",")

            @channels.synchronize do
                    m[0].split(",").each do |chan|
                            init_channel(chan)
                            info = @channels[chan]
                            if info
                                    users.each do |nick|
                                            info[:users].delete(nick)
                                            info[:modes].delete_if {|u|
                                                    u[1] == nick
                                            }
                                    end
                            end
                    end
            end
    end

on_mode(m) click to toggle source

For managing channel

    # File lib/net/irc/client/channel_manager.rb, line 116
    def on_mode(m)
            channel = m[0]
            @channels.synchronize do
                    init_channel(channel)

                    modes = @server_config.mode_parser.parse(m)
                    modes[:negative].each do |mode|
                            @channels[channel][:modes].delete(mode)
                    end

                    modes[:positive].each do |mode|
                            @channels[channel][:modes] << mode
                    end

                    @channels[channel][:modes].uniq!
                    [modes[:negative], modes[:positive]]
            end
    end

on_nick(m) click to toggle source

For managing channel

    # File lib/net/irc/client/channel_manager.rb, line 99
    def on_nick(m)
            oldnick = m.prefix.nick
            newnick = m[0]

            @channels.synchronize do
                    @channels.each do |channel, info|
                            info[:users].map! {|i|
                                    (i == oldnick) ? newnick : i
                            }
                            info[:modes].map! {|mode, target|
                                    (target == oldnick) ? [mode, newnick] : [mode, target]
                            }
                    end
            end
    end

on_part(m) click to toggle source

For managing channel

    # File lib/net/irc/client/channel_manager.rb, line 35
    def on_part(m)
            nick    = m.prefix.nick
            channel = m[0]
            init_channel(channel)

            @channels.synchronize do
                    info = @channels[channel]
                    if info
                            info[:users].delete(nick)
                            info[:modes].delete_if {|u|
                                    u[1] == nick
                            }
                    end
            end
    end

on_quit(m) click to toggle source

For managing channel

    # File lib/net/irc/client/channel_manager.rb, line 52
    def on_quit(m)
            nick = m.prefix.nick

            @channels.synchronize do
                    @channels.each do |channel, info|
                            info[:users].delete(nick)
                            info[:modes].delete_if {|u|
                                    u[1] == nick
                            }
                    end
            end
    end

on_rpl_namreply(m) click to toggle source

For managing channel

    # File lib/net/irc/client/channel_manager.rb, line 4
    def on_rpl_namreply(m)
            type    = m[1]
            channel = m[2]
            init_channel(channel)

            @channels.synchronize do
                    m[3].split(" ").each do |u|
                            _, mode, nick = *u.match(/\A([@+]?)(.+)/)

                            @channels[channel][:users] << nick
                            @channels[channel][:users].uniq!

                            op = @server_config.mode_parser.mark_to_op(mode)
                            if op
                                    @channels[channel][:modes] << [op, nick]
                            end
                    end

                    case type
                    when "@" # secret
                            @channels[channel][:modes] << [:s, nil]
                    when "*" # private
                            @channels[channel][:modes] << [:p, nil]
                    when "=" # public
                    end

                    @channels[channel][:modes].uniq!
            end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.