ircguerilla-irc 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,87 @@
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 85 2006-08-13 11:42:07Z roman $
25
+ #
26
+ require 'irc/messages/message'
27
+ require 'irc/messages/invalid_message'
28
+
29
+ module IRC
30
+
31
+ module Messages
32
+
33
+ # 4.4.2 Notice
34
+ #
35
+ # Command: NOTICE
36
+ # Parameters: <nickname> <text>
37
+ #
38
+ # The NOTICE message is used similarly to PRIVMSG. The difference between NOTICE and PRIVMSG is
39
+ # that automatic replies must never be sent in response to a NOTICE message. This rule applies
40
+ # to servers too - they must not send any error reply back to the client on receipt of a notice.
41
+ # The object of this rule is to avoid loops between a client automatically sending something in
42
+ # response to something it received. This is typically used by automatons (clients with either
43
+ # an AI or other interactive program controlling their actions) which are always seen to be
44
+ # replying lest they end up in a loop with another automaton.
45
+ #
46
+ # See PRIVMSG for more details on replies and examples.
47
+ #
48
+ class NoticeMessage < Message
49
+
50
+ CODE = "NOTICE"
51
+
52
+ attr_reader :message
53
+
54
+ # Notify all connection listeners, that a notice message was received.
55
+ def handle(context)
56
+
57
+ # Notify all connection listeners by calling their on_server_response method.
58
+ super(context)
59
+
60
+ # Notify all connection listeners by calling their on_notice method.
61
+ notify(context) do |connection_listener|
62
+ connection_listener.on_notice(context, context.lookup_user(nick), message)
63
+ end
64
+
65
+ end
66
+
67
+ protected
68
+
69
+ def parse(raw_message)
70
+
71
+ # Initialize the base message fields.
72
+ super(raw_message)
73
+
74
+ # Match the message against the message format.
75
+ match_data = Regexp.new('\s*NOTICE\s+:?(\S+)\s+:?(.*)').match(raw_message)
76
+ raise InvalidMessage.new("Can't parse notice message. Invalid message format.") unless match_data
77
+
78
+ # Initialize the nick & message fileds.
79
+ @nick, @message = match_data[1].strip, match_data[2].strip
80
+
81
+ end
82
+
83
+ end
84
+
85
+ end
86
+
87
+ end
@@ -0,0 +1,95 @@
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
+ # 4.2.2 Part message
35
+ #
36
+ # Command: PART
37
+ # Parameters: <channel>{,<channel>}
38
+ #
39
+ # The PART message causes the client sending the message to be removed
40
+ # from the list of active users for all given channels listed in the
41
+ # parameter string.
42
+ #
43
+ # Numeric Replies:
44
+ #
45
+ # ERR_NEEDMOREPARAMS
46
+ # ERR_NOSUCHCHANNEL
47
+ # ERR_NOTONCHANNEL
48
+ #
49
+ # Examples:
50
+ #
51
+ # PART #twilight_zone ; leave channel "#twilight_zone"
52
+ #
53
+ # PART #oz-ops,&group5 ; leave both channels "&group5" and
54
+ # ; "#oz-ops".
55
+ #
56
+ class PartMessage < Message
57
+
58
+ CODE = "PART"
59
+
60
+ attr_reader :channel
61
+
62
+ # Notify all connection listeners, that a user has left a channel.
63
+ def handle(context)
64
+
65
+ # Notify all connection listeners by calling their on_server_response method.
66
+ super(context)
67
+
68
+ # Notify all connection listeners by calling their on_part method.
69
+ notify(context) do |connection_listener|
70
+ connection_listener.on_part(context, context.lookup_channel(channel), context.lookup_user(nick))
71
+ end
72
+
73
+ end
74
+
75
+ protected
76
+
77
+ def parse(raw_message)
78
+
79
+ # Initialize the base message fields.
80
+ super(raw_message)
81
+
82
+ # Extract the message specific fields.
83
+ match_data = Regexp.new(':?(.+)').match(message)
84
+ raise InvalidMessage.new("Can't parse part message. Invalid message format.") if match_data == nil || code != CODE
85
+
86
+ # Extract the channel name.
87
+ @channel = match_data[1]
88
+
89
+ end
90
+
91
+ end
92
+
93
+ end
94
+
95
+ end
@@ -0,0 +1,101 @@
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: ping_message.rb 93 2006-08-13 21:30:53Z roman $
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
+ # 4.6.2 Ping message
35
+ #
36
+ # Command: PING
37
+ # Parameters: <server1> [<server2>]
38
+ #
39
+ # The PING message is used to test the presence of an active client at the other end of
40
+ # the connection. A PING message is sent at regular intervals if no other activity detected
41
+ # coming from a connection. If a connection fails to respond to a PING command within a set
42
+ # amount of time, that connection is closed.
43
+ #
44
+ # Any client which receives a PING message must respond to <server1> (server which sent the
45
+ # PING message out) as quickly as possible with an appropriate PONG message to indicate it
46
+ # is still there and alive. Servers should not respond to PING commands but rely on PINGs
47
+ # from the other end of the connection to indicate the connection is alive. If the <server2>
48
+ # parameter is specified, the PING message gets forwarded there.
49
+ #
50
+ # Numeric Replies:
51
+ # * ERR_NOORIGIN
52
+ # * ERR_NOSUCHSERVER
53
+ #
54
+ # Examples:
55
+ #
56
+ # PING tolsun.oulu.fi ; server sending a PING message to
57
+ # another server to indicate it is still
58
+ # alive.
59
+ #
60
+ # PING WiZ ; PING message being sent to nick WiZ
61
+ #
62
+ class PingMessage < Message
63
+
64
+ CODE = "PING"
65
+
66
+ attr_reader :servers
67
+
68
+ # Notify all connection listeners, that a ping message was received.
69
+ def handle(context)
70
+
71
+ # Notify all connection listeners by calling their on_server_response method.
72
+ super(context)
73
+
74
+ # Notify all connection listeners by calling their on_ping method.
75
+ notify(context) do |connection_listener|
76
+ connection_listener.on_ping(context, servers)
77
+ end
78
+
79
+ end
80
+
81
+ protected
82
+
83
+ def parse(raw_message)
84
+
85
+ # Initialize the base message fields.
86
+ super(raw_message)
87
+
88
+ # Extract the message specific fields.
89
+ match_data = Regexp.new(':?([^\s:]+)(\s+:?(.+))?').match(message)
90
+ raise InvalidMessage.new("Can't parse ping message. Invalid message format.") if match_data == nil || code != CODE
91
+
92
+ # Extract the servers and strip white spaces.
93
+ @servers = [match_data[1], match_data[3]].compact.map! { |element| element.strip }
94
+
95
+ end
96
+
97
+ end
98
+
99
+ end
100
+
101
+ end
@@ -0,0 +1,89 @@
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: pong_message.rb 93 2006-08-13 21:30:53Z roman $
25
+ #
26
+ require 'irc/messages/message'
27
+ require 'irc/messages/invalid_message'
28
+
29
+ module IRC
30
+
31
+ module Messages
32
+
33
+ # 4.6.3 Pong message
34
+ #
35
+ # Command: PONG
36
+ # Parameters: <daemon> [<daemon2>]
37
+ #
38
+ # PONG message is a reply to ping message. If parameter <daemon2> is given this message must
39
+ # be forwarded to given daemon. The <daemon> parameter is the name of the daemon who has responded
40
+ # to PING message and generated this message.
41
+ #
42
+ # Numeric Replies:
43
+ # * ERR_NOORIGIN
44
+ # * ERR_NOSUCHSERVER
45
+ #
46
+ # Examples:
47
+ #
48
+ # PONG csd.bu.edu tolsun.oulu.fi ; PONG message from csd.bu.edu to
49
+ #
50
+ class PongMessage < Message
51
+
52
+ CODE = "PONG"
53
+
54
+ attr_reader :daemons
55
+
56
+ # Notify all message listeners, that a pong message was received.
57
+ def handle(context)
58
+
59
+ # Notify all connection listeners by calling their on_server_response method.
60
+ super(context)
61
+
62
+ # Notify all connection listeners by calling their on_pong method.
63
+ notify(context) do |connection_listener|
64
+ message_listener.on_pong(context, daemons)
65
+ end
66
+
67
+ end
68
+
69
+ protected
70
+
71
+ def parse(raw_message)
72
+
73
+ # Initialize the base message fields.
74
+ super(raw_message)
75
+
76
+ # Extract the message specific fields.
77
+ match_data = Regexp.new(':?([^\s:]+)(\s+:?(.+))?').match(message)
78
+ raise InvalidMessage.new("Can't parse ping message. Invalid message format.") if match_data == nil || code != CODE
79
+
80
+ # Extract the servers and strip white spaces.
81
+ @daemons = [match_data[1], match_data[3]].compact.map! { |element| element.strip }
82
+
83
+ end
84
+
85
+ end
86
+
87
+ end
88
+
89
+ end
@@ -0,0 +1,121 @@
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/messages/message'
27
+ require 'irc/messages/invalid_message'
28
+ require 'irc/models/channel'
29
+
30
+ module IRC
31
+
32
+ module Messages
33
+
34
+ # 4.4.1 Private messages
35
+ #
36
+ # Command: PRIVMSG
37
+ # Parameters: <receiver>{,<receiver>} <text to be sent>
38
+ #
39
+ # PRIVMSG is used to send private messages between users. <receiver> is the nickname
40
+ # of the receiver of the message. <receiver> can also be a list of names or channels
41
+ # separated with commas.
42
+ #
43
+ # The <receiver> parameter may also me a host mask (#mask) or server mask ($mask). In
44
+ # both cases the server will only send the PRIVMSG to those who have a server or host
45
+ # matching the mask. The mask must have at least 1 (one) "." in it and no wildcards
46
+ # following the last ".". This requirement exists to prevent people sending messages
47
+ # to "#*" or "$*", which would broadcast to all users; from experience, this is abused
48
+ # more than used responsibly and properly. Wildcards are the '*' and '?' characters.
49
+ # This extension to the PRIVMSG command is only available to Operators.
50
+ #
51
+ # Numeric Replies:
52
+ # * ERR_NORECIPIENT
53
+ # * ERR_NOTEXTTOSEND
54
+ # * ERR_CANNOTSENDTOCHAN
55
+ # * ERR_NOTOPLEVEL
56
+ # * ERR_WILDTOPLEVEL
57
+ # * ERR_TOOMANYTARGETS
58
+ # * ERR_NOSUCHNICK
59
+ # * RPL_AWAY
60
+ #
61
+ # Examples:
62
+ #
63
+ # :Angel PRIVMSG Wiz :Hello are you receiving this message ?
64
+ # ; Message from Angel to Wiz.
65
+ #
66
+ # PRIVMSG Angel :yes I'm receiving it !receiving it !'u>(768u+1n) .br
67
+ # ; Message to Angel.
68
+ #
69
+ # PRIVMSG jto@tolsun.oulu.fi :Hello !
70
+ # ; Message to a client on server
71
+ # tolsun.oulu.fi with username of "jto".
72
+ #
73
+ # PRIVMSG $*.fi :Server tolsun.oulu.fi rebooting.
74
+ # ; Message to everyone on a server which
75
+ # has a name matching *.fi.
76
+ #
77
+ # PRIVMSG #*.edu :NSFNet is undergoing work, expect interruptions
78
+ # ; Message to all users who come from a
79
+ # host which has a name matching *.edu.
80
+ class PrivateMessage < Message
81
+
82
+ CODE = "PRIVMSG"
83
+
84
+ attr_reader :target
85
+ attr_reader :sender
86
+ attr_reader :text
87
+
88
+ # Notify all connection listeners, that a private message was received.
89
+ def handle(context)
90
+
91
+ # Notify all connection listeners by calling their on_server_response method.
92
+ super(context)
93
+
94
+ # Notify all connection listeners by calling their on_private_message method.
95
+ notify(context) do |connection_listener|
96
+ connection_listener.on_private_message(context, IRC::Models::Channel.is_valid?(target) ? context.lookup_channel(target) : context.lookup_user(target), text)
97
+ end
98
+
99
+ end
100
+
101
+ protected
102
+
103
+ def parse(raw_message)
104
+
105
+ # Initialize the base message fields.
106
+ super(raw_message)
107
+
108
+ # Extract the message specific fields.
109
+ match_data = Regexp.new('(\S+)\s+:?(.+)').match(message)
110
+ raise InvalidMessage.new("Can't parse private message. Invalid message format.") if match_data == nil || code != CODE
111
+
112
+ # Extract the sender, target and the text.
113
+ @sender, @target, @text = nick, match_data[1], match_data[2]
114
+
115
+ end
116
+
117
+ end
118
+
119
+ end
120
+
121
+ end