Class: IRC::Commands::JoinCommand
- Defined in:
- lib/irc/commands/join_command.rb
Overview
4.2.1 Join message
Command: JOIN Parameters: <channel>,<channel> [<key>,<key>]
The JOIN command is used by client to start listening a specific channel. Whether or not a client is allowed to join a channel is checked only by the server the client is connected to; all other servers automatically add the user to the channel when it is received from other servers. The conditions which affect this are as follows:
1. the user must be invited if the channel is invite-only;
2. the user's nick/username/hostname must not match any active bans;
3. the correct key (password) must be given if it is set.
These are discussed in more detail under the MODE command (see section 4.2.3 for more details).
Once a user has joined a channel, they receive notice about all commands their server receives which affect the channel. This includes MODE, KICK, PART, QUIT and of course PRIVMSG/NOTICE. The JOIN command needs to be broadcast to all servers so that each server knows where to find the users who are on the channel. This allows optimal delivery of PRIVMSG/NOTICE messages to the channel.
If a JOIN is successful, the user is then sent the channel’s topic (using RPL_TOPIC) and the list of users who are on the channel (using RPL_NAMREPLY), which must include the user joining.
Numeric Replies:
-
ERR_NEEDMOREPARAMS
-
ERR_BANNEDFROMCHAN
-
ERR_INVITEONLYCHAN
-
ERR_BADCHANNELKEY
-
ERR_CHANNELISFULL
-
ERR_BADCHANMASK
-
ERR_NOSUCHCHANNEL
-
ERR_TOOMANYCHANNELS
-
RPL_TOPIC
Examples:
JOIN #foobar ; join channel #foobar.
JOIN &foo fubar ; join channel &foo using key “fubar”.
JOIN #foo,&bar fubar ; join channel #foo using key “fubar”
; and &bar using no key.
JOIN #foo,#bar fubar,foobar ; join channel #foo using key “fubar”.
; and channel #bar using key "foobar".
JOIN #foo,#bar ; join channels #foo and #bar.
:WiZ JOIN #Twilight_zone ; JOIN message from WiZ
Instance Attribute Summary collapse
-
#channels ⇒ Object
readonly
Returns the value of attribute channels.
-
#passwords ⇒ Object
readonly
Returns the value of attribute passwords.
Attributes inherited from Command
Instance Method Summary collapse
- #command ⇒ Object
-
#initialize(channels, passwords = []) ⇒ JoinCommand
constructor
A new instance of JoinCommand.
-
#valid_response?(message) ⇒ Boolean
Returns true, if the message is a valid response to the command.
Methods inherited from Command
#execute, #on_server_response, #to_s, #wait
Methods included from IRC::Client::ConnectionListener
#on_connect, #on_disconnect, #on_error, #on_join, #on_join_failure, #on_kick, #on_nick, #on_nick_already_in_use, #on_notice, #on_part, #on_part_failure, #on_ping, #on_pong, #on_private_message, #on_registration, #on_registration_failure, #on_server_response, #on_welcome
Constructor Details
#initialize(channels, passwords = []) ⇒ JoinCommand
Returns a new instance of JoinCommand.
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/irc/commands/join_command.rb', line 95 def initialize(channels, passwords = []) raise InvalidCommand.new("Can't create join command. No channels.") unless channels if channels.instance_of?(Array) @channels = channels else @channels = Array.new @channels << channels end if passwords.instance_of?(Array) @passwords = passwords else @passwords = Array.new @passwords << passwords end super(command) end |
Instance Attribute Details
#channels ⇒ Object (readonly)
Returns the value of attribute channels.
92 93 94 |
# File 'lib/irc/commands/join_command.rb', line 92 def channels @channels end |
#passwords ⇒ Object (readonly)
Returns the value of attribute passwords.
93 94 95 |
# File 'lib/irc/commands/join_command.rb', line 93 def passwords @passwords end |
Instance Method Details
#command ⇒ Object
117 118 119 |
# File 'lib/irc/commands/join_command.rb', line 117 def command return "JOIN #{channels.join(',')} #{passwords.join(',')}".strip end |
#valid_response?(message) ⇒ Boolean
Returns true, if the message is a valid response to the command.
122 123 124 125 126 127 128 129 130 131 |
# File 'lib/irc/commands/join_command.rb', line 122 def valid_response?() valid_reponse_codes = [IRC::Messages::Codes::ERR_NEEDMOREPARAMS, IRC::Messages::Codes::ERR_BANNEDFROMCHAN, IRC::Messages::Codes::ERR_INVITEONLYCHAN, IRC::Messages::Codes::ERR_BADCHANNELKEY, IRC::Messages::Codes::ERR_CHANNELISFULL, IRC::Messages::Codes::ERR_BADCHANMASK, IRC::Messages::Codes::ERR_NOSUCHCHANNEL, IRC::Messages::Codes::ERR_TOOMANYCHANNELS, IRC::Messages::Codes::RPL_TOPIC] return valid_reponse_codes.include?(.code) end |