ircguerilla-irc 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. data/lib/irc/client/client_error.rb +35 -0
  2. data/lib/irc/client/command_handler.rb +113 -0
  3. data/lib/irc/client/connected_state.rb +95 -0
  4. data/lib/irc/client/connection.rb +119 -0
  5. data/lib/irc/client/connection_listener.rb +97 -0
  6. data/lib/irc/client/connection_state.rb +88 -0
  7. data/lib/irc/client/context.rb +250 -0
  8. data/lib/irc/client/disconnected_state.rb +132 -0
  9. data/lib/irc/client/message_handler.rb +87 -0
  10. data/lib/irc/client/registered_state.rb +90 -0
  11. data/lib/irc/client/unregistered_state.rb +113 -0
  12. data/lib/irc/commands/command.rb +57 -0
  13. data/lib/irc/commands/invalid_command.rb +35 -0
  14. data/lib/irc/commands/join_command.rb +122 -0
  15. data/lib/irc/commands/nick_command.rb +86 -0
  16. data/lib/irc/commands/part_command.rb +84 -0
  17. data/lib/irc/commands/password_command.rb +72 -0
  18. data/lib/irc/commands/ping_command.rb +79 -0
  19. data/lib/irc/commands/pong_command.rb +68 -0
  20. data/lib/irc/commands/quit_command.rb +77 -0
  21. data/lib/irc/commands/user_command.rb +105 -0
  22. data/lib/irc/messages/codes.rb +186 -0
  23. data/lib/irc/messages/error_join_message.rb +72 -0
  24. data/lib/irc/messages/error_message.rb +101 -0
  25. data/lib/irc/messages/factory.rb +122 -0
  26. data/lib/irc/messages/invalid_message.rb +35 -0
  27. data/lib/irc/messages/join_message.rb +130 -0
  28. data/lib/irc/messages/message.rb +110 -0
  29. data/lib/irc/messages/nick_message.rb +93 -0
  30. data/lib/irc/messages/notice_message.rb +87 -0
  31. data/lib/irc/messages/part_message.rb +95 -0
  32. data/lib/irc/messages/ping_message.rb +101 -0
  33. data/lib/irc/messages/pong_message.rb +89 -0
  34. data/lib/irc/messages/private_message.rb +121 -0
  35. data/lib/irc/models/bot.rb +159 -0
  36. data/lib/irc/models/channel.rb +158 -0
  37. data/lib/irc/models/network.rb +252 -0
  38. data/lib/irc/models/packet.rb +84 -0
  39. data/lib/irc/models/server.rb +116 -0
  40. data/lib/irc/models/user.rb +112 -0
  41. data/test/functional/irc/client/connection_test.rb +118 -0
  42. data/test/functional/irc/client/context_test.rb +126 -0
  43. data/test/test_helper.rb +32 -0
  44. data/test/unit/irc/client/command_handler_test.rb +137 -0
  45. data/test/unit/irc/commands/join_command_test.rb +72 -0
  46. data/test/unit/irc/commands/nick_command_test.rb +35 -0
  47. data/test/unit/irc/commands/part_command_test.rb +52 -0
  48. data/test/unit/irc/commands/password_command_test.rb +35 -0
  49. data/test/unit/irc/commands/ping_command_test.rb +36 -0
  50. data/test/unit/irc/commands/pong_command_test.rb +36 -0
  51. data/test/unit/irc/commands/quit_command_test.rb +35 -0
  52. data/test/unit/irc/commands/user_command_test.rb +35 -0
  53. data/test/unit/irc/messages/error_join_message_test.rb +45 -0
  54. data/test/unit/irc/messages/factory_test.rb +62 -0
  55. data/test/unit/irc/messages/join_message_test.rb +46 -0
  56. data/test/unit/irc/messages/message_test.rb +56 -0
  57. data/test/unit/irc/messages/nick_message_test.rb +48 -0
  58. data/test/unit/irc/messages/notice_message_test.rb +43 -0
  59. data/test/unit/irc/messages/part_message_test.rb +47 -0
  60. data/test/unit/irc/messages/ping_message_test.rb +57 -0
  61. data/test/unit/irc/messages/pong_message_test.rb +57 -0
  62. data/test/unit/irc/messages/private_message_test.rb +42 -0
  63. data/test/unit/irc/models/bot_test.rb +85 -0
  64. data/test/unit/irc/models/channel_test.rb +90 -0
  65. data/test/unit/irc/models/network_test.rb +210 -0
  66. data/test/unit/irc/models/packet_test.rb +38 -0
  67. data/test/unit/irc/models/server_test.rb +54 -0
  68. data/test/unit/irc/models/user_test.rb +67 -0
  69. metadata +111 -0
@@ -0,0 +1,122 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Copyright (c) 2006 Roman Scherer | IRC Guerilla | Rapid Packet Movement
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ #
24
+ # $Id: factory.rb 93 2006-08-13 21:30:53Z roman $
25
+ #
26
+ require 'irc/messages/message'
27
+ require 'irc/messages/error_message'
28
+ require 'irc/messages/join_message'
29
+ require 'irc/messages/nick_message'
30
+ require 'irc/messages/notice_message'
31
+ require 'irc/messages/part_message'
32
+ require 'irc/messages/ping_message'
33
+ require 'irc/messages/pong_message'
34
+
35
+ module IRC
36
+
37
+ module Messages
38
+
39
+ class Factory
40
+
41
+ def self.create(raw_message)
42
+
43
+ # Remove new line from raw message if available.
44
+ raw_message.chomp!
45
+
46
+ # Create a new message object, to get access to the message code.
47
+ message = Message.new(raw_message)
48
+
49
+ # Create a new specialized message object, depending on the message code.
50
+ case message.code
51
+
52
+ when ErrorAlreadyRegisteredMessage::CODE
53
+ return ErrorAlreadyRegisteredMessage.new(raw_message)
54
+
55
+ when ErrorBadChannelKeyMessage::CODE
56
+ return ErrorBadChannelKeyMessage.new(raw_message)
57
+
58
+ when ErrorBadChannelMaskMessage::CODE
59
+ return ErrorBadChannelMaskMessage.new(raw_message)
60
+
61
+ when ErrorBannedFromChannelMessage::CODE
62
+ return ErrorBannedFromChannelMessage.new(raw_message)
63
+
64
+ when ErrorChannelIsFulMessage::CODE
65
+ return ErrorChannelIsFulMessage.new(raw_message)
66
+
67
+ when ErrorErroneusNickNameMessage::CODE
68
+ return ErrorErroneusNickNameMessage.new(raw_message)
69
+
70
+ when ErrorInviteOnlyChannelMessage::CODE
71
+ return ErrorInviteOnlyChannelMessage.new(raw_message)
72
+
73
+ when ErrorNeedMoreParametersMessage::CODE
74
+ return ErrorNeedMoreParametersMessage.new(raw_message)
75
+
76
+ when ErrorNickCollisionMessage::CODE
77
+ return ErrorNickCollisionMessage.new(raw_message)
78
+
79
+ when ErrorNickNameInUseMessage::CODE
80
+ return ErrorNickNameInUseMessage.new(raw_message)
81
+
82
+ when ErrorNoNickNameGivenMessage::CODE
83
+ return ErrorNoNickNameGivenMessage.new(raw_message)
84
+
85
+ when ErrorNoSuchChannelMessage::CODE
86
+ return ErrorNoSuchChannelMessage.new(raw_message)
87
+
88
+ when ErrorNotOnChannelMessage::CODE
89
+ return ErrorNotOnChannelMessage.new(raw_message)
90
+
91
+ when ErrorTooManyChannelsMessage::CODE
92
+ return ErrorTooManyChannelsMessage.new(raw_message)
93
+
94
+ when JoinMessage::CODE
95
+ return JoinMessage.new(raw_message)
96
+
97
+ when NickMessage::CODE
98
+ return NickMessage.new(raw_message)
99
+
100
+ when NoticeMessage::CODE
101
+ return NoticeMessage.new(raw_message)
102
+
103
+ when PartMessage::CODE
104
+ return PartMessage.new(raw_message)
105
+
106
+ when PingMessage::CODE
107
+ return PingMessage.new(raw_message)
108
+
109
+ when PongMessage::CODE
110
+ return PongMessage.new(raw_message)
111
+
112
+ end
113
+
114
+ return message
115
+
116
+ end
117
+
118
+ end
119
+
120
+ end
121
+
122
+ end
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Copyright (c) 2006 Roman Scherer | IRC Guerilla | Rapid Packet Movement
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ #
24
+ # $Id: invalid_message.rb 85 2006-08-13 11:42:07Z roman $
25
+ #
26
+ module IRC
27
+
28
+ module Messages
29
+
30
+ class InvalidMessage < Exception
31
+ end
32
+
33
+ end
34
+
35
+ end
@@ -0,0 +1,130 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Copyright (c) 2006 Roman Scherer | IRC Guerilla | Rapid Packet Movement
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ #
24
+ # $Id$
25
+ #
26
+ require 'irc/commands/pong_command'
27
+ require 'irc/messages/message'
28
+ require 'irc/messages/invalid_message'
29
+
30
+ module IRC
31
+
32
+ module Messages
33
+
34
+
35
+ # 4.2.1 Join message
36
+ #
37
+ # Command: JOIN
38
+ # Parameters: <channel>{,<channel>} [<key>{,<key>}]
39
+ #
40
+ # The JOIN command is used by client to start listening a specific channel.
41
+ # Whether or not a client is allowed to join a channel is checked only by
42
+ # the server the client is connected to; all other servers automatically add
43
+ # the user to the channel when it is received from other servers. The conditions
44
+ # which affect this are as follows:
45
+ #
46
+ # 1. the user must be invited if the channel is invite-only;
47
+ # 2. the user's nick/username/hostname must not match any active bans;
48
+ # 3. the correct key (password) must be given if it is set.
49
+ #
50
+ # These are discussed in more detail under the MODE command (see section 4.2.3
51
+ # for more details).
52
+ #
53
+ # Once a user has joined a channel, they receive notice about all commands their
54
+ # server receives which affect the channel. This includes MODE, KICK, PART, QUIT
55
+ # and of course PRIVMSG/NOTICE. The JOIN command needs to be broadcast to all
56
+ # servers so that each server knows where to find the users who are on the channel.
57
+ # This allows optimal delivery of PRIVMSG/NOTICE messages to the channel.
58
+ #
59
+ # If a JOIN is successful, the user is then sent the channel's topic (using
60
+ # RPL_TOPIC) and the list of users who are on the channel (using RPL_NAMREPLY),
61
+ # which must include the user joining.
62
+ #
63
+ # Numeric Replies:
64
+ #
65
+ # * ERR_NEEDMOREPARAMS
66
+ # * ERR_BANNEDFROMCHAN
67
+ # * ERR_INVITEONLYCHAN
68
+ # * ERR_BADCHANNELKEY
69
+ # * ERR_CHANNELISFULL
70
+ # * ERR_BADCHANMASK
71
+ # * ERR_NOSUCHCHANNEL
72
+ # * ERR_TOOMANYCHANNELS
73
+ # * RPL_TOPIC
74
+ #
75
+ # Examples:
76
+ #
77
+ # JOIN #foobar ; join channel #foobar.
78
+ #
79
+ # JOIN &foo fubar ; join channel &foo using key "fubar".
80
+ #
81
+ # JOIN #foo,&bar fubar ; join channel #foo using key "fubar"
82
+ # ; and &bar using no key.
83
+ #
84
+ # JOIN #foo,#bar fubar,foobar ; join channel #foo using key "fubar".
85
+ # ; and channel #bar using key "foobar".
86
+ #
87
+ # JOIN #foo,#bar ; join channels #foo and #bar.
88
+ #
89
+ # :WiZ JOIN #Twilight_zone ; JOIN message from WiZ
90
+ #
91
+ class JoinMessage < Message
92
+
93
+ CODE = "JOIN"
94
+
95
+ attr_reader :channel
96
+
97
+ # Notify all connection listeners, that a user has joined a channel.
98
+ def handle(context)
99
+
100
+ # Notify all connection listeners by calling their on_server_response method.
101
+ super(context)
102
+
103
+ # Notify all connection listeners by calling their on_join method.
104
+ notify(context) do |connection_listener|
105
+ connection_listener.on_join(context, context.lookup_channel(channel), context.lookup_user(nick))
106
+ end
107
+
108
+ end
109
+
110
+ protected
111
+
112
+ def parse(raw_message)
113
+
114
+ # Initialize the base message fields.
115
+ super(raw_message)
116
+
117
+ # Extract the message specific fields.
118
+ match_data = Regexp.new(':?(.+)').match(message)
119
+ raise InvalidMessage.new("Can't parse join message. Invalid message format.") if match_data == nil || code != CODE
120
+
121
+ # Extract the channel name.
122
+ @channel = match_data[1]
123
+
124
+ end
125
+
126
+ end
127
+
128
+ end
129
+
130
+ end
@@ -0,0 +1,110 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Copyright (c) 2006 Roman Scherer | IRC Guerilla | Rapid Packet Movement
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ #
24
+ # $Id: message.rb 93 2006-08-13 21:30:53Z roman $
25
+ #
26
+ require 'pp'
27
+ require 'irc/messages/codes'
28
+ require 'irc/messages/invalid_message'
29
+
30
+ module IRC
31
+
32
+ module Messages
33
+
34
+ class Message
35
+
36
+ include Codes
37
+
38
+ MESSAGE_FORMAT = Regexp.new('(:([^!\s]+)(!([^@\s]+))?(@(\S+))?\s+)?(\w+|\d\d\d)\s+(.*)')
39
+
40
+ attr_reader :code
41
+ attr_reader :host
42
+ attr_reader :message
43
+ attr_reader :nick
44
+ attr_reader :raw_message
45
+ attr_reader :server
46
+ attr_reader :login
47
+
48
+ def initialize(raw_message)
49
+ parse(raw_message)
50
+ end
51
+
52
+ # Notify all connection listeners that a message was received from the IRC server,
53
+ # by calling their on_server_response method.
54
+ def handle(context)
55
+
56
+ # Notify all connection listeners by calling their on_server_response method.
57
+ notify(context) do |connection_listener|
58
+ connection_listener.on_server_response(context, self)
59
+ end
60
+
61
+ end
62
+
63
+ # Returns true if the given string matches the IRC message format, else false.
64
+ def self.is_valid?(raw_message)
65
+ return Regexp.new(MESSAGE_FORMAT).match(raw_message) != nil
66
+ end
67
+
68
+ protected
69
+
70
+ # Notify all connection listeners, by calling the surrounding block with a channel listener as parameter.
71
+ def notify(context)
72
+
73
+ context.connection_listeners.each do |connection_listener|
74
+ yield connection_listener
75
+ end
76
+
77
+ end
78
+
79
+ def parse(raw_message)
80
+
81
+ # Throw an exception if the given message doesn't match the IRC message format.
82
+ raise InvalidMessage.new("Can't create message. Invalid IRC message format.") unless Message.is_valid?(raw_message)
83
+
84
+ # Save the raw message for later use.
85
+ @raw_message = raw_message
86
+
87
+ # Parse the raw message & initialize the IRC message fields.
88
+ match_data = MESSAGE_FORMAT.match(raw_message)
89
+
90
+ # Extract nick & server.
91
+ @nick = match_data[2]
92
+ @server = match_data[4] != nil || match_data[6] != nil ? nil : match_data[2]
93
+
94
+ # Extract the login & host name.
95
+ @login = match_data[4]
96
+ @host = match_data[6]
97
+
98
+ # Extract the IRC message code. If the code is a number, convert it to an integer.
99
+ @code = (match_data[7] =~ /\d+/ ? match_data[7].to_i : match_data[7])
100
+
101
+ # Extract the rest of the message. The message is everything after the IRC message code.
102
+ @message = match_data[8]
103
+
104
+ end
105
+
106
+ end
107
+
108
+ end
109
+
110
+ end
@@ -0,0 +1,93 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Copyright (c) 2006 Roman Scherer | IRC Guerilla | Rapid Packet Movement
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ #
24
+ # $Id: nick_message.rb 89 2006-08-13 14:03:35Z roman $
25
+ #
26
+ require 'irc/messages/message'
27
+ require 'irc/messages/invalid_message'
28
+
29
+ module IRC
30
+
31
+ module Messages
32
+
33
+ # 4.1.2 Nick message
34
+ #
35
+ # Command: NICK
36
+ # Parameters: <nickname> [ <hopcount> ]
37
+ #
38
+ # NICK message is used to give user a nickname or change the previous one. The
39
+ # <hopcount> parameter is only used by servers to indicate how far away a nick
40
+ # is from its home server. A local connection has a hopcount of 0. If supplied
41
+ # by a client, it must be ignored.
42
+ #
43
+ # If a NICK message arrives at a server which already knows about an identical
44
+ # nickname for another client, a nickname collision occurs. As a result of a
45
+ # nickname collision, all instances of the nickname are removed from the server's
46
+ # database, and a KILL command is issued to remove the nickname from all other
47
+ # server's database. If the NICK message causing the collision was a nickname
48
+ # change, then the original (old) nick must be removed as well.
49
+ #
50
+ # If the server recieves an identical NICK from a client which is directly
51
+ # connected, it may issue an ERR_NICKCOLLISION to the local client, drop the NICK
52
+ # command, and not generate any kills.
53
+ #
54
+ # Numeric Replies:
55
+ #
56
+ # ERR_NONICKNAMEGIVEN
57
+ # ERR_ERRONEUSNICKNAME
58
+ # ERR_NICKNAMEINUSE
59
+ # ERR_NICKCOLLISION
60
+ #
61
+ # Example:
62
+ #
63
+ # NICK Wiz ; Introducing new nick "Wiz".
64
+ #
65
+ # :WiZ NICK Kilroy ; WiZ changed his nickname to Kilroy.
66
+ #
67
+ class NickMessage < Message
68
+
69
+ CODE = "NICK"
70
+
71
+ attr_reader :after
72
+ attr_reader :before
73
+
74
+ def parse(raw_message)
75
+
76
+ # Initialize the base message fields.
77
+ super(raw_message)
78
+
79
+ # Match the message against the message format.
80
+ match_data = Regexp.new('\s*:?(\S+)\s+NICK\s+(\S+)\s*').match(raw_message)
81
+ raise InvalidMessage.new("Can't parse nick message. Invalid message format.") unless match_data
82
+
83
+ # Initialize the variables holding the nick names before & after the nick change.
84
+ @after = match_data[2]
85
+ @before = match_data[1]
86
+
87
+ end
88
+
89
+ end
90
+
91
+ end
92
+
93
+ end