Class: IRC::Client::RegisteredState
- Inherits:
-
ConnectedState
- Object
- ConnectionState
- ConnectedState
- IRC::Client::RegisteredState
- Defined in:
- lib/irc/client/registered_state.rb
Instance Method Summary collapse
-
#change_nick(context, nick) ⇒ Object
Changes the nick name.
-
#connect(context, server) ⇒ Object
Connects to the server.
-
#initialize ⇒ RegisteredState
constructor
A new instance of RegisteredState.
-
#join(context, channels) ⇒ Object
Joins the given channels.
-
#on_join(context, channel, user) ⇒ Object
This method gets called when a user (possibly us) joins a channel.
-
#on_join_failure(context, channel, code, reason) ⇒ Object
This message gets called when a channel join attempt failed.
-
#on_kick(context, channel, kick_user, kicked_user, reason) ⇒ Object
This method gets called when a user gets kicked from a channel.
-
#on_nick_already_in_use(context, nick_name) ⇒ Object
This method gets called when the chosen nick name is already in use.
-
#on_part(context, channel, user) ⇒ Object
This method gets called when a user (possibly us) leaves a channel.
-
#on_part_failure(connection, channel) ⇒ Object
This method gets called when a channel part attempt failed.
-
#part(context, channels) ⇒ Object
Leaves the given channels.
-
#register(context, nick, login, realname) ⇒ Object
Register the connection by sending the password, nick and user commands.
Methods inherited from ConnectedState
#disconnect, #on_disconnect, #on_error, #on_nick, #on_ping
Methods inherited from ConnectionState
#disconnect, #on_ping, #on_welcome, #private_message, #send_command, #send_command_via_queue
Methods included from ConnectionListener
#on_connect, #on_disconnect, #on_error, #on_nick, #on_notice, #on_ping, #on_pong, #on_private_message, #on_registration, #on_registration_failure, #on_server_response, #on_welcome
Constructor Details
#initialize ⇒ RegisteredState
Returns a new instance of RegisteredState.
39 40 41 |
# File 'lib/irc/client/registered_state.rb', line 39 def initialize @log = Log4r::Logger.new('IRC::Client::RegisteredState') end |
Instance Method Details
#change_nick(context, nick) ⇒ Object
Changes the nick name.
44 45 46 |
# File 'lib/irc/client/registered_state.rb', line 44 def change_nick(context, nick) IRC::Commands::NickCommand.new(nick).execute(context) end |
#connect(context, server) ⇒ Object
Connects to the server.
49 50 51 |
# File 'lib/irc/client/registered_state.rb', line 49 def connect(context, server) raise ClientError.new("Can't connect to server. Already connected to a server.") end |
#join(context, channels) ⇒ Object
Joins the given channels.
54 55 56 |
# File 'lib/irc/client/registered_state.rb', line 54 def join(context, channels) IRC::Commands::JoinCommand.new(channels).execute(context) end |
#on_join(context, channel, user) ⇒ Object
This method gets called when a user (possibly us) joins a channel.
71 72 73 74 75 |
# File 'lib/irc/client/registered_state.rb', line 71 def on_join(context, channel, user) return unless context.nick.strip.downcase == user.nick.strip.downcase context.join_succeeded(channel) @log.debug("#{network_name(context)} Successfully joined channel #{channel}.") end |
#on_join_failure(context, channel, code, reason) ⇒ Object
This message gets called when a channel join attempt failed.
78 79 80 |
# File 'lib/irc/client/registered_state.rb', line 78 def on_join_failure(context, channel, code, reason) @log.debug("#{network_name(context)} Failed to join channel #{channel}. #{reason.capitalize}.") end |
#on_kick(context, channel, kick_user, kicked_user, reason) ⇒ Object
This method gets called when a user gets kicked from a channel.
83 84 |
# File 'lib/irc/client/registered_state.rb', line 83 def on_kick(context, channel, kick_user, kicked_user, reason) end |
#on_nick_already_in_use(context, nick_name) ⇒ Object
This method gets called when the chosen nick name is already in use.
87 88 89 90 91 |
# File 'lib/irc/client/registered_state.rb', line 87 def on_nick_already_in_use(context, nick_name) return unless context.auto_nick_change raise ClientError("Maximum number of nick name changes reached. Giving up!") if context.nick_generator.names.empty? context.change_nick(context.nick_generator.pop) end |
#on_part(context, channel, user) ⇒ Object
This method gets called when a user (possibly us) leaves a channel.
94 95 96 97 98 |
# File 'lib/irc/client/registered_state.rb', line 94 def on_part(context, channel, user) return unless context.nick.strip.downcase == user.nick.strip.downcase context.part_succeeded(channel) @log.debug("#{network_name(context)} Successfully left channel #{channel}.") end |
#on_part_failure(connection, channel) ⇒ Object
This method gets called when a channel part attempt failed.
101 102 |
# File 'lib/irc/client/registered_state.rb', line 101 def on_part_failure(connection, channel) end |
#part(context, channels) ⇒ Object
Leaves the given channels.
59 60 61 |
# File 'lib/irc/client/registered_state.rb', line 59 def part(context, channels) IRC::Commands::PartCommand.new(channels).execute(context) end |
#register(context, nick, login, realname) ⇒ Object
Register the connection by sending the password, nick and user commands.
64 65 66 |
# File 'lib/irc/client/registered_state.rb', line 64 def register(context, nick, login, realname) raise ClientError.new("Can't register connection again. Already registered.") end |