ircsupport 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.md +8 -0
- data/README.md +6 -3
- data/ircsupport.gemspec +2 -1
- data/lib/ircsupport/case.rb +7 -7
- data/lib/ircsupport/encoding.rb +6 -4
- data/lib/ircsupport/formatting.rb +10 -6
- data/lib/ircsupport/masks.rb +5 -2
- data/lib/ircsupport/message.rb +19 -21
- data/lib/ircsupport/modes.rb +9 -5
- data/lib/ircsupport/numerics.rb +4 -2
- data/lib/ircsupport/parser.rb +15 -11
- data/lib/ircsupport/validations.rb +4 -2
- data/lib/ircsupport/version.rb +1 -1
- data/test/encoding_test.rb +4 -4
- data/test/message_test.rb +16 -13
- data/test/test_coverage.rb +3 -6
- metadata +69 -25
data/CHANGES.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
0.2.0
|
2
|
+
-----
|
3
|
+
* Add missing `#ctcp_type` and `#dcc_type` accessors
|
4
|
+
* Make `#type, `#ctcp_type`, and `#dcc_type` return symbols, not strings
|
5
|
+
* Rename `#numeric_name` to `#name`
|
6
|
+
* Remove superfluous `#numeric` and `#numeric_args` (use `#command` and `#args`)
|
7
|
+
* Depend on Ruby 1.9.2 and use Float::INFINITY for some ISupport defaults
|
8
|
+
|
1
9
|
0.1.0
|
2
10
|
-----
|
3
11
|
* Initial release
|
data/README.md
CHANGED
@@ -48,7 +48,7 @@ msg.is_action?
|
|
48
48
|
# => false
|
49
49
|
|
50
50
|
msg.type
|
51
|
-
# =>
|
51
|
+
# => :message
|
52
52
|
|
53
53
|
IRCSupport::Validations.valid_nick_name?("Foo{}Bar[]")
|
54
54
|
# => true
|
@@ -65,6 +65,9 @@ numeric_to_name('001')
|
|
65
65
|
# => 'RPL_WELCOME'
|
66
66
|
```
|
67
67
|
|
68
|
+
See the [API documentation](http://rubydoc.info/github/hinrik/ircsupport) for
|
69
|
+
more details.
|
70
|
+
|
68
71
|
Components
|
69
72
|
----------
|
70
73
|
|
@@ -109,8 +112,8 @@ Supported platforms
|
|
109
112
|
-------------------
|
110
113
|
|
111
114
|
IRCSupport works on any Ruby 1.9-compatible VM. As of this writing, Rubinius'
|
112
|
-
|
113
|
-
`IRCSupport::Encoding` will not work on
|
115
|
+
encoding support is not complete, so some of the functions in
|
116
|
+
`IRCSupport::Encoding` will not work on that platform.
|
114
117
|
|
115
118
|
Contributing
|
116
119
|
------------
|
data/ircsupport.gemspec
CHANGED
@@ -16,11 +16,12 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.test_files = `git ls-files -- test/*`.split("\n")
|
17
17
|
gem.require_path = "lib"
|
18
18
|
gem.has_rdoc = "yard"
|
19
|
-
gem.required_ruby_version = '>= 1.9.
|
19
|
+
gem.required_ruby_version = '>= 1.9.2'
|
20
20
|
|
21
21
|
gem.add_development_dependency "rake"
|
22
22
|
gem.add_development_dependency "simplecov"
|
23
23
|
gem.add_development_dependency "yard", ">= 0.7.5"
|
24
|
+
gem.add_development_dependency "redcarpet"
|
24
25
|
gem.add_development_dependency "minitest", ">= 2.11.4"
|
25
26
|
gem.add_development_dependency "turn"
|
26
27
|
end
|
data/lib/ircsupport/case.rb
CHANGED
@@ -7,9 +7,11 @@ module IRCSupport
|
|
7
7
|
# @private
|
8
8
|
@@strict_rfc1459_map = ['a-z{}|', 'A-Z[]\\']
|
9
9
|
|
10
|
+
module_function
|
11
|
+
|
12
|
+
# Turn a string into IRC upper case, modifying it in place.
|
10
13
|
# @param [String] irc_string An IRC string (nickname, channel, etc).
|
11
14
|
# @param [Symbol] casemapping An IRC casemapping.
|
12
|
-
# Like {#irc_upcase}, but modifies the string in place.
|
13
15
|
# @return [String] An upper case version of the IRC string according to
|
14
16
|
# the casemapping.
|
15
17
|
def irc_upcase!(irc_string, casemapping = :rfc1459)
|
@@ -19,7 +21,6 @@ module IRCSupport
|
|
19
21
|
when :rfc1459
|
20
22
|
irc_string.tr!(*@@rfc1459_map)
|
21
23
|
when :'strict-rfc1459'
|
22
|
-
# the backslash must be last, otherwise it causes issues
|
23
24
|
irc_string.tr!(*@@strict_rfc1459_map)
|
24
25
|
else
|
25
26
|
raise ArgumentError, "Unsupported casemapping #{casemapping}"
|
@@ -28,6 +29,7 @@ module IRCSupport
|
|
28
29
|
return irc_string
|
29
30
|
end
|
30
31
|
|
32
|
+
# Turn a string into IRC upper case.
|
31
33
|
# @param [String] irc_string An IRC string (nickname, channel, etc)
|
32
34
|
# @param [Symbol] casemapping An IRC casemapping
|
33
35
|
# @return [String] An upper case version of the IRC string according to
|
@@ -38,9 +40,9 @@ module IRCSupport
|
|
38
40
|
return result
|
39
41
|
end
|
40
42
|
|
43
|
+
# Turn a string into IRC lower case, modifying it in place.
|
41
44
|
# @param [String] irc_string An IRC string (nickname, channel, etc)
|
42
45
|
# @param [Symbol] casemapping An IRC casemapping
|
43
|
-
# Like {#irc_downcase}, but modifies the string in place.
|
44
46
|
# @return [String] A lower case version of the IRC string according to
|
45
47
|
# the casemapping
|
46
48
|
def irc_downcase!(irc_string, casemapping = :rfc1459)
|
@@ -50,7 +52,6 @@ module IRCSupport
|
|
50
52
|
when :rfc1459
|
51
53
|
irc_string.tr!(*@@rfc1459_map.reverse)
|
52
54
|
when :'strict-rfc1459'
|
53
|
-
# the backslash must be last, otherwise it causes issues
|
54
55
|
irc_string.tr!(*@@strict_rfc1459_map.reverse)
|
55
56
|
else
|
56
57
|
raise ArgumentError, "Unsupported casemapping #{casemapping}"
|
@@ -59,6 +60,7 @@ module IRCSupport
|
|
59
60
|
return irc_string
|
60
61
|
end
|
61
62
|
|
63
|
+
# Turn a string into IRC lower case.
|
62
64
|
# @param [String] irc_string An IRC string (nickname, channel, etc).
|
63
65
|
# @param [Symbol] casemapping An IRC casemapping.
|
64
66
|
# @return [String] A lower case version of the IRC string according to
|
@@ -69,6 +71,7 @@ module IRCSupport
|
|
69
71
|
return result
|
70
72
|
end
|
71
73
|
|
74
|
+
# Check an IRC identifier (nick, channel) for equality.
|
72
75
|
# @param [String] first The first IRC string to compare.
|
73
76
|
# @param [String] second The second IRC string to compare.
|
74
77
|
# @param [Symbol] casemapping The IRC casemappig to use for the comparison.
|
@@ -77,8 +80,5 @@ module IRCSupport
|
|
77
80
|
def irc_eql?(first, second, casemapping = :rfc1459)
|
78
81
|
return irc_upcase(first, casemapping) == irc_upcase(second, casemapping)
|
79
82
|
end
|
80
|
-
|
81
|
-
module_function :irc_upcase, :irc_upcase!, :irc_downcase,
|
82
|
-
:irc_downcase!, :irc_eql?
|
83
83
|
end
|
84
84
|
end
|
data/lib/ircsupport/encoding.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
module IRCSupport
|
2
2
|
module Encoding
|
3
|
+
module_function
|
4
|
+
|
5
|
+
# Decode a message from an IRC connection.
|
3
6
|
# @param [String] string The IRC string you want to decode.
|
4
7
|
# @param [Symbol] encoding The source encoding.
|
5
8
|
# @return [String] A UTF-8 Ruby string.
|
@@ -8,6 +11,7 @@ module IRCSupport
|
|
8
11
|
decode_irc!(string, encoding)
|
9
12
|
end
|
10
13
|
|
14
|
+
# Encode a message to be sent over an IRC connection.
|
11
15
|
# @param [String] string The string you want to encode.
|
12
16
|
# @param [Symbol] encoding The target encoding.
|
13
17
|
# @return [String] A string encoded in the encoding you specified.
|
@@ -16,9 +20,9 @@ module IRCSupport
|
|
16
20
|
encode_irc!(string, encoding)
|
17
21
|
end
|
18
22
|
|
23
|
+
# Decode a message from an IRC connection, modifying it in place.
|
19
24
|
# @param [String] string The IRC string you want to decode.
|
20
25
|
# @param [Symbol] encoding The source encoding.
|
21
|
-
# Like {#decode_irc}, but modifies the string in place.
|
22
26
|
# @return [String] A UTF-8 Ruby string.
|
23
27
|
def decode_irc!(string, encoding = :irc)
|
24
28
|
if encoding == :irc
|
@@ -40,9 +44,9 @@ module IRCSupport
|
|
40
44
|
return string
|
41
45
|
end
|
42
46
|
|
47
|
+
# Encode a message to be sent over an IRC connection, modifying it in place.
|
43
48
|
# @param [String] string The string you want to encode.
|
44
49
|
# @param [Symbol] encoding The target encoding.
|
45
|
-
# Like {#encode_irc}, but modifies the string in place.
|
46
50
|
# @return [String] A string encoded in the encoding you specified.
|
47
51
|
def encode_irc!(string, encoding = :irc)
|
48
52
|
if encoding == :irc
|
@@ -68,7 +72,5 @@ module IRCSupport
|
|
68
72
|
|
69
73
|
return string
|
70
74
|
end
|
71
|
-
|
72
|
-
module_function :decode_irc, :decode_irc!, :encode_irc, :encode_irc!
|
73
75
|
end
|
74
76
|
end
|
@@ -47,6 +47,9 @@ module IRCSupport
|
|
47
47
|
silver: "15",
|
48
48
|
}
|
49
49
|
|
50
|
+
module_function
|
51
|
+
|
52
|
+
# Check if string has IRC color codes.
|
50
53
|
# @param [String] string The string you want to check.
|
51
54
|
# @return [Boolean] Will be true if the string contains IRC color codes.
|
52
55
|
def has_color?(string)
|
@@ -54,6 +57,7 @@ module IRCSupport
|
|
54
57
|
return false
|
55
58
|
end
|
56
59
|
|
60
|
+
# Check if string has IRC formatting codes.
|
57
61
|
# @param [String] string The string you want to check.
|
58
62
|
# @return [Boolean] Will be true if the string contains IRC formatting codes.
|
59
63
|
def has_formatting?(string)
|
@@ -61,8 +65,8 @@ module IRCSupport
|
|
61
65
|
return false
|
62
66
|
end
|
63
67
|
|
68
|
+
# Strip IRC color codes from a string, modifying it in place.
|
64
69
|
# @param [String] string The string you want to strip.
|
65
|
-
# Like {#strip_color}, but modifies the string in place.
|
66
70
|
# @return [String] A string stripped of all IRC color codes.
|
67
71
|
def strip_color!(string)
|
68
72
|
[@@mirc_color, @@rgb_color, @@ecma48_color].each do |pattern|
|
@@ -73,6 +77,7 @@ module IRCSupport
|
|
73
77
|
return string
|
74
78
|
end
|
75
79
|
|
80
|
+
# Strip IRC color codes from a string.
|
76
81
|
# @param [String] string The string you want to strip.
|
77
82
|
# @return [String] A string stripped of all IRC color codes.
|
78
83
|
def strip_color(string)
|
@@ -80,8 +85,8 @@ module IRCSupport
|
|
80
85
|
return strip_color!(string)
|
81
86
|
end
|
82
87
|
|
88
|
+
# Strip IRC formatting codes from a string, modifying it in place.
|
83
89
|
# @param [String] string The string you want to strip.
|
84
|
-
# Like {#strip_formatting}, but modifies the string in place.
|
85
90
|
# @return [String] A string stripped of all IRC formatting codes.
|
86
91
|
def strip_formatting!(string)
|
87
92
|
string.gsub!(@@formatting, '')
|
@@ -90,6 +95,7 @@ module IRCSupport
|
|
90
95
|
return string
|
91
96
|
end
|
92
97
|
|
98
|
+
# Strip IRC formatting codes from a string.
|
93
99
|
# @param [String] string The string you want to strip.
|
94
100
|
# @return [String] A string stripped of all IRC formatting codes.
|
95
101
|
def strip_formatting(string)
|
@@ -97,9 +103,9 @@ module IRCSupport
|
|
97
103
|
return strip_formatting!(string)
|
98
104
|
end
|
99
105
|
|
106
|
+
# Apply IRC formatting codes to a string, modifying it in place.
|
100
107
|
# @param [*Array] settings A list of color and formatting attributes you
|
101
108
|
# want to apply.
|
102
|
-
# Like {#irc_format}, but modifies the string in place.
|
103
109
|
# @param [String] string A string you want to format.
|
104
110
|
# @return [String] A formatted string.
|
105
111
|
def irc_format!(*settings, string)
|
@@ -134,6 +140,7 @@ module IRCSupport
|
|
134
140
|
return string
|
135
141
|
end
|
136
142
|
|
143
|
+
# Apply IRC formatting codes to a string.
|
137
144
|
# @param [*Array] settings A list of color and formatting attributes you
|
138
145
|
# want to apply.
|
139
146
|
# @param [String] string A string you want to format.
|
@@ -142,8 +149,5 @@ module IRCSupport
|
|
142
149
|
string = string.dup
|
143
150
|
return irc_format!(*settings, string)
|
144
151
|
end
|
145
|
-
|
146
|
-
module_function :has_color?, :has_formatting?, :strip_color, :strip_color!,
|
147
|
-
:strip_formatting, :strip_formatting!, :irc_format
|
148
152
|
end
|
149
153
|
end
|
data/lib/ircsupport/masks.rb
CHANGED
@@ -7,6 +7,9 @@ module IRCSupport
|
|
7
7
|
# @private
|
8
8
|
@@mask_optional = '[\x01-\xFF]{1,1}'
|
9
9
|
|
10
|
+
module_function
|
11
|
+
|
12
|
+
# Match strings to an IRC mask.
|
10
13
|
# @param [String] mask The mask to match against.
|
11
14
|
# @param [String] string The string to match against the mask.
|
12
15
|
# @param [Symbol] casemapping The IRC casemapping to use in the match.
|
@@ -24,6 +27,7 @@ module IRCSupport
|
|
24
27
|
return false
|
25
28
|
end
|
26
29
|
|
30
|
+
# Match strings to multiple IRC masks.
|
27
31
|
# @param [Array] mask The masks to match against.
|
28
32
|
# @param [Array] strings The strings to match against the masks.
|
29
33
|
# @param [Symbol] casemapping The IRC casemapping to use in the match.
|
@@ -42,6 +46,7 @@ module IRCSupport
|
|
42
46
|
return results
|
43
47
|
end
|
44
48
|
|
49
|
+
# Normalize (expand) an IRC mask.
|
45
50
|
# @param [String] mask A partial mask (e.g. 'foo*').
|
46
51
|
# @return [String] A normalized mask (e.g. 'foo*!*@*).
|
47
52
|
def normalize_mask(mask)
|
@@ -66,7 +71,5 @@ module IRCSupport
|
|
66
71
|
(1..2).each { |i| parts[i] ||= '*' }
|
67
72
|
return parts[0] + "!" + parts[1] + "@" + parts[2]
|
68
73
|
end
|
69
|
-
|
70
|
-
module_function :matches_mask, :matches_mask_array, :normalize_mask
|
71
74
|
end
|
72
75
|
end
|
data/lib/ircsupport/message.rb
CHANGED
@@ -23,33 +23,25 @@ module IRCSupport
|
|
23
23
|
# @return [String] The type of the IRC message.
|
24
24
|
def type
|
25
25
|
return @type if @type
|
26
|
-
return @command.downcase if self.class.name == 'IRCSupport::Message'
|
26
|
+
return @command.downcase.to_sym if self.class.name == 'IRCSupport::Message'
|
27
27
|
type = self.class.name.match(/^IRCSupport::Message::(.*)/)[1]
|
28
|
-
return type.gsub(/::|(?<=[[:lower:]])(?=[[:upper:]])/, '_').downcase
|
28
|
+
return type.gsub(/::|(?<=[[:lower:]])(?=[[:upper:]])/, '_').downcase.to_sym
|
29
29
|
end
|
30
30
|
|
31
31
|
class Numeric < Message
|
32
|
-
# @return [String] The IRC command numeric.
|
33
|
-
attr_accessor :
|
34
|
-
|
35
|
-
# @return [String] The name of the IRC command numeric.
|
36
|
-
attr_accessor :numeric_name
|
37
|
-
|
38
|
-
# @return [String] The arguments to the numeric command.
|
39
|
-
attr_accessor :numeric_args
|
32
|
+
# @return [String] The name of the IRC command numeric (e.g. RPL_WELCOME).
|
33
|
+
attr_accessor :name
|
40
34
|
|
41
35
|
# @private
|
42
36
|
def initialize(args)
|
43
37
|
super(args)
|
44
|
-
@
|
45
|
-
@
|
46
|
-
@numeric_name = IRCSupport::Numerics.numeric_to_name(@numeric)
|
47
|
-
@type = @numeric
|
38
|
+
@name = IRCSupport::Numerics.numeric_to_name(@command)
|
39
|
+
@type = @command.to_sym
|
48
40
|
end
|
49
41
|
|
50
42
|
# @return [Boolean] Will be true if this is an error numeric.
|
51
43
|
def is_error?
|
52
|
-
return @
|
44
|
+
return @name =~ /^ERR/ ? true : false
|
53
45
|
end
|
54
46
|
end
|
55
47
|
|
@@ -194,6 +186,9 @@ module IRCSupport
|
|
194
186
|
# @return [String] The sender of the DCC message.
|
195
187
|
attr_accessor :sender
|
196
188
|
|
189
|
+
# @return [Symbol] The type of the DCC message.
|
190
|
+
attr_accessor :dcc_type
|
191
|
+
|
197
192
|
# @return [String] The argument string to the DCC message.
|
198
193
|
attr_accessor :dcc_args
|
199
194
|
|
@@ -202,8 +197,8 @@ module IRCSupport
|
|
202
197
|
super(args)
|
203
198
|
@sender = args[:prefix]
|
204
199
|
@dcc_args = args[:args][1]
|
205
|
-
@dcc_type = args[:dcc_type]
|
206
|
-
@type = "dcc_
|
200
|
+
@dcc_type = args[:dcc_type].downcase.to_sym
|
201
|
+
@type = "dcc_#@dcc_type".to_sym
|
207
202
|
end
|
208
203
|
end
|
209
204
|
|
@@ -481,7 +476,7 @@ module IRCSupport
|
|
481
476
|
def initialize(args)
|
482
477
|
super(args)
|
483
478
|
@subcommand = args[:args][0]
|
484
|
-
@type = "cap_#{@subcommand.downcase}"
|
479
|
+
@type = "cap_#{@subcommand.downcase}".to_sym
|
485
480
|
if args[:args][1] == '*'
|
486
481
|
@multipart = true
|
487
482
|
@reply = args[:args][2]
|
@@ -588,6 +583,9 @@ module IRCSupport
|
|
588
583
|
end
|
589
584
|
|
590
585
|
class CTCP < Message
|
586
|
+
# @return [String] The type of the CTCP message.
|
587
|
+
attr_accessor :ctcp_type
|
588
|
+
|
591
589
|
# @return [String] The arguments to the CTCP.
|
592
590
|
attr_accessor :ctcp_args
|
593
591
|
|
@@ -596,8 +594,8 @@ module IRCSupport
|
|
596
594
|
super(args)
|
597
595
|
@sender = args[:prefix]
|
598
596
|
@ctcp_args = args[:args][1]
|
599
|
-
@ctcp_type = args[:ctcp_type]
|
600
|
-
@type = "ctcp_
|
597
|
+
@ctcp_type = args[:ctcp_type].downcase.to_sym
|
598
|
+
@type = "ctcp_#@ctcp_type".to_sym
|
601
599
|
|
602
600
|
if args[:is_public]
|
603
601
|
@channel = args[:args][0].split(/,/).first
|
@@ -609,7 +607,7 @@ module IRCSupport
|
|
609
607
|
# @private
|
610
608
|
def initialize(args)
|
611
609
|
super(args)
|
612
|
-
@type = "ctcpreply_
|
610
|
+
@type = "ctcpreply_#@ctcp_type".to_sym
|
613
611
|
end
|
614
612
|
end
|
615
613
|
end
|
data/lib/ircsupport/modes.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
module IRCSupport
|
2
2
|
module Modes
|
3
|
-
|
3
|
+
module_function
|
4
|
+
|
5
|
+
# Parse mode changes.
|
6
|
+
# @param [Array] modes The modes you want to parse. A string of mode
|
7
|
+
# changes (e.g. `'-i+k+l'`) followed by any arguments (e.g. `'secret', 25`).
|
4
8
|
# @return [Array] Each element will be a hash with two keys: `:set`,
|
5
9
|
# a boolean indicating whether the mode is being set (instead of unset);
|
6
10
|
# and `:mode`, the mode character.
|
@@ -16,6 +20,7 @@ module IRCSupport
|
|
16
20
|
return mode_changes
|
17
21
|
end
|
18
22
|
|
23
|
+
# Parse channel mode changes.
|
19
24
|
# @param [Array] modes The modes you want to parse.
|
20
25
|
# @option opts [Hash] :chanmodes The channel modes which are allowed. This is
|
21
26
|
# the same as the "CHANMODES" isupport option.
|
@@ -64,8 +69,8 @@ module IRCSupport
|
|
64
69
|
return mode_changes
|
65
70
|
end
|
66
71
|
|
67
|
-
#
|
68
|
-
#
|
72
|
+
# Condense mode string by removing duplicates.
|
73
|
+
# @param [String] modes A string of modes you want condensed.
|
69
74
|
# @return [Strings] A condensed mode string.
|
70
75
|
def condense_modes(modes)
|
71
76
|
action = nil
|
@@ -82,6 +87,7 @@ module IRCSupport
|
|
82
87
|
return result
|
83
88
|
end
|
84
89
|
|
90
|
+
# Calculate the difference between two mode strings.
|
85
91
|
# @param [String] before The "before" mode string.
|
86
92
|
# @param [String] after The "after" mode string.
|
87
93
|
# @return [String] A modestring representing the difference between the
|
@@ -95,7 +101,5 @@ module IRCSupport
|
|
95
101
|
result << added.map { |m| '+' + m }.join
|
96
102
|
return condense_modes(result)
|
97
103
|
end
|
98
|
-
|
99
|
-
module_function :parse_modes, :parse_channel_modes, :condense_modes, :diff_modes
|
100
104
|
end
|
101
105
|
end
|
data/lib/ircsupport/numerics.rb
CHANGED
@@ -225,18 +225,20 @@ module IRCSupport
|
|
225
225
|
# @private
|
226
226
|
@@name_to_numeric_map = @@numeric_to_name_map.invert
|
227
227
|
|
228
|
+
module_function
|
229
|
+
|
230
|
+
# Look up the name of an IRC numeric.
|
228
231
|
# @param [String] numeric A numeric to look up.
|
229
232
|
# @return [String] The name of the numeric.
|
230
233
|
def numeric_to_name(numeric)
|
231
234
|
return @@numeric_to_name_map[numeric]
|
232
235
|
end
|
233
236
|
|
237
|
+
# Look up an IRC numeric by name.
|
234
238
|
# @param [String] name A name to look up.
|
235
239
|
# @return [String] The numeric corresponding to the name.
|
236
240
|
def name_to_numeric(name)
|
237
241
|
return @@name_to_numeric_map[name]
|
238
242
|
end
|
239
|
-
|
240
|
-
module_function :numeric_to_name, :name_to_numeric
|
241
243
|
end
|
242
244
|
end
|
data/lib/ircsupport/parser.rb
CHANGED
@@ -54,16 +54,16 @@ module IRCSupport
|
|
54
54
|
"D" => %w[i m n p s t r]
|
55
55
|
},
|
56
56
|
"MODES" => 1,
|
57
|
-
"NICKLEN" =>
|
58
|
-
"MAXBANS" =>
|
59
|
-
"TOPICLEN" =>
|
60
|
-
"KICKLEN" =>
|
61
|
-
"CHANNELLEN" =>
|
57
|
+
"NICKLEN" => Float::INFINITY,
|
58
|
+
"MAXBANS" => Float::INFINITY,
|
59
|
+
"TOPICLEN" => Float::INFINITY,
|
60
|
+
"KICKLEN" => Float::INFINITY,
|
61
|
+
"CHANNELLEN" => Float::INFINITY,
|
62
62
|
"CHIDLEN" => 5,
|
63
|
-
"AWAYLEN" =>
|
63
|
+
"AWAYLEN" => Float::INFINITY,
|
64
64
|
"MAXTARGETS" => 1,
|
65
|
-
"MAXCHANNELS" =>
|
66
|
-
"CHANLIMIT" => {"#" =>
|
65
|
+
"MAXCHANNELS" => Float::INFINITY,
|
66
|
+
"CHANLIMIT" => {"#" => Float::INFINITY},
|
67
67
|
"STATUSMSG" => ["@", "+"],
|
68
68
|
"CASEMAPPING" => :rfc1459,
|
69
69
|
"ELIST" => [],
|
@@ -81,12 +81,13 @@ module IRCSupport
|
|
81
81
|
# @return [Array]
|
82
82
|
attr_reader :capabilities
|
83
83
|
|
84
|
-
# @
|
84
|
+
# @private
|
85
85
|
def initialize
|
86
86
|
@isupport = @@default_isupport
|
87
87
|
@capabilities = []
|
88
88
|
end
|
89
89
|
|
90
|
+
# Perform low-level parsing of an IRC protocol line.
|
90
91
|
# @param [String] line An IRC protocol line you wish to decompose.
|
91
92
|
# @return [Hash] A decomposed IRC protocol line with 3 keys:
|
92
93
|
# `command`, the IRC command; `prefix`, the prefix to the
|
@@ -107,6 +108,7 @@ module IRCSupport
|
|
107
108
|
return elems
|
108
109
|
end
|
109
110
|
|
111
|
+
# Compose an IRC protocol line.
|
110
112
|
# @param [Hash] elems The attributes of the message (as returned
|
111
113
|
# by {#decompose_line}).
|
112
114
|
# @return [String] An IRC protocol line.
|
@@ -134,6 +136,7 @@ module IRCSupport
|
|
134
136
|
return line
|
135
137
|
end
|
136
138
|
|
139
|
+
# Parse an IRC protocol line into a complete message object.
|
137
140
|
# @param [String] line An IRC protocol line.
|
138
141
|
# @return [IRCSupport::Message] A parsed message object.
|
139
142
|
def parse(line)
|
@@ -190,9 +193,9 @@ module IRCSupport
|
|
190
193
|
|
191
194
|
message = msg_const.new(elems)
|
192
195
|
|
193
|
-
if message.type == '005'
|
196
|
+
if message.type == :'005'
|
194
197
|
@isupport.merge! message.isupport
|
195
|
-
elsif message.type ==
|
198
|
+
elsif message.type == :cap_ack
|
196
199
|
message.capabilities.each do |capability, options|
|
197
200
|
if options.include?(:disable)
|
198
201
|
@capabilities = @capabilities - [capability]
|
@@ -205,6 +208,7 @@ module IRCSupport
|
|
205
208
|
return message
|
206
209
|
end
|
207
210
|
|
211
|
+
# CTCP-quote a message.
|
208
212
|
# @param [String] type The CTCP type.
|
209
213
|
# @param [String] message The text of the CTCP message.
|
210
214
|
# @return [String] A CTCP-quoted message.
|
@@ -10,6 +10,9 @@ module IRCSupport
|
|
10
10
|
# @private
|
11
11
|
@@channel = /[^\x00\x07\x0a\x0d :,]+/
|
12
12
|
|
13
|
+
module_function
|
14
|
+
|
15
|
+
# Check if a string is a valid nickname.
|
13
16
|
# @param [String] nickname A nickname to validate.
|
14
17
|
# @return [Boolean] Will be true if the nickname is valid.
|
15
18
|
def valid_nickname?(nickname)
|
@@ -17,6 +20,7 @@ module IRCSupport
|
|
17
20
|
return false
|
18
21
|
end
|
19
22
|
|
23
|
+
# Check if a string is a valid channel name.
|
20
24
|
# @param [String] channel A channel name to validate.
|
21
25
|
# @param [Array] chantypes The channel types which are allowed. This is
|
22
26
|
# the same as the "CHANTYPES" isupport option.
|
@@ -27,7 +31,5 @@ module IRCSupport
|
|
27
31
|
return true if channel =~ /\A[#{prefix}]#@@channel\z/
|
28
32
|
return false
|
29
33
|
end
|
30
|
-
|
31
|
-
module_function :valid_nickname?, :valid_channel_name?
|
32
34
|
end
|
33
35
|
end
|
data/lib/ircsupport/version.rb
CHANGED
data/test/encoding_test.rb
CHANGED
@@ -9,8 +9,8 @@ describe "Encoding" do
|
|
9
9
|
cp1252 = "l\xFA\xF0i"
|
10
10
|
|
11
11
|
it "should decode correctly" do
|
12
|
-
if
|
13
|
-
skip("Encoding support is incomplete on
|
12
|
+
if RUBY_ENGINE == "rbx"
|
13
|
+
skip("Encoding support is incomplete on Rubinius")
|
14
14
|
end
|
15
15
|
decode_irc(utf8).must_equal utf8
|
16
16
|
decode_irc(utf8, 'UTF-8').must_equal utf8
|
@@ -18,8 +18,8 @@ describe "Encoding" do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should encode correctly" do
|
21
|
-
if
|
22
|
-
skip("Encoding support is incomplete on
|
21
|
+
if RUBY_ENGINE == "rbx"
|
22
|
+
skip("Encoding support is incomplete on Rubinius")
|
23
23
|
end
|
24
24
|
encode_irc(utf8).bytes.to_a.must_equal cp1252.bytes.to_a
|
25
25
|
encode_irc(utf8, 'UTF-8').bytes.to_a.must_equal utf8.bytes.to_a
|
data/test/message_test.rb
CHANGED
@@ -19,8 +19,8 @@ traffic = [
|
|
19
19
|
msg.command.must_equal '001'
|
20
20
|
msg.args[0].must_equal 'dsfdsfdsf'
|
21
21
|
msg.args[1].must_equal 'Welcome to the freenode Internet Relay Chat Network dsfdsfdsf'
|
22
|
-
msg.type.must_equal '001'
|
23
|
-
msg.
|
22
|
+
msg.type.must_equal :'001'
|
23
|
+
msg.name.must_equal 'RPL_WELCOME'
|
24
24
|
msg.is_error?.must_equal false
|
25
25
|
},
|
26
26
|
],
|
@@ -84,7 +84,7 @@ traffic = [
|
|
84
84
|
[
|
85
85
|
':NickServ!NickServ@services. NOTICE dsfdsfdsf :+This nickname is registered. Please choose a different nickname, or identify via /msg NickServ identify <password>.',
|
86
86
|
->(msg) {
|
87
|
-
msg.type.must_equal
|
87
|
+
msg.type.must_equal :message
|
88
88
|
msg.is_notice?.must_equal true
|
89
89
|
msg.sender.must_equal 'NickServ!NickServ@services.'
|
90
90
|
msg.identified?.must_equal true
|
@@ -128,21 +128,24 @@ traffic = [
|
|
128
128
|
[
|
129
129
|
":literal!hinrik@w.nix.is PRIVMSG #foo4321 :\x01FOOBAR dsfdsfsdfds\x01",
|
130
130
|
->(msg) {
|
131
|
-
msg.type.must_equal
|
131
|
+
msg.type.must_equal :ctcp_foobar
|
132
|
+
msg.ctcp_type.must_equal :foobar
|
132
133
|
msg.ctcp_args.must_equal 'dsfdsfsdfds'
|
133
134
|
},
|
134
135
|
],
|
135
136
|
[
|
136
137
|
":literal!hinrik@w.nix.is NOTICE #foo4321 :\x01FOOBAR dsfdsfsdfds\x01",
|
137
138
|
->(msg) {
|
138
|
-
msg.type.must_equal
|
139
|
+
msg.type.must_equal :ctcpreply_foobar
|
140
|
+
msg.ctcp_type.must_equal :foobar
|
139
141
|
msg.ctcp_args.must_equal 'dsfdsfsdfds'
|
140
142
|
},
|
141
143
|
],
|
142
144
|
[
|
143
145
|
":literal!hinrik@w.nix.is PRIVMSG #foo4321 :\x01DCC FOO dsfdsfsdfds\x01",
|
144
146
|
->(msg) {
|
145
|
-
msg.type.must_equal
|
147
|
+
msg.type.must_equal :dcc_foo
|
148
|
+
msg.dcc_type.must_equal :foo
|
146
149
|
msg.sender.must_equal 'literal!hinrik@w.nix.is'
|
147
150
|
msg.dcc_args.must_equal 'dsfdsfsdfds'
|
148
151
|
},
|
@@ -294,7 +297,7 @@ traffic = [
|
|
294
297
|
[
|
295
298
|
'NOTICE :foo bar',
|
296
299
|
->(msg) {
|
297
|
-
msg.type.must_equal
|
300
|
+
msg.type.must_equal :server_notice
|
298
301
|
msg.sender.must_equal nil
|
299
302
|
msg.target.must_equal nil
|
300
303
|
msg.message.must_equal 'foo bar'
|
@@ -303,7 +306,7 @@ traffic = [
|
|
303
306
|
[
|
304
307
|
':fooserver NOTICE AUTH :foo bar',
|
305
308
|
->(msg) {
|
306
|
-
msg.type.must_equal
|
309
|
+
msg.type.must_equal :server_notice
|
307
310
|
msg.sender.must_equal 'fooserver'
|
308
311
|
msg.target.must_equal 'AUTH'
|
309
312
|
msg.message.must_equal 'foo bar'
|
@@ -312,7 +315,7 @@ traffic = [
|
|
312
315
|
[
|
313
316
|
':foo-service NOTICE :foo bar',
|
314
317
|
->(msg) {
|
315
|
-
msg.type.must_equal
|
318
|
+
msg.type.must_equal :server_notice
|
316
319
|
msg.sender.must_equal 'foo-service'
|
317
320
|
msg.message.must_equal 'foo bar'
|
318
321
|
},
|
@@ -321,7 +324,7 @@ traffic = [
|
|
321
324
|
'CAP LS :foo -bar ~baz ~=quux',
|
322
325
|
->(msg) {
|
323
326
|
msg.multipart.must_equal false
|
324
|
-
msg.type.must_equal
|
327
|
+
msg.type.must_equal :cap_ls
|
325
328
|
msg.subcommand.must_equal 'LS'
|
326
329
|
msg.reply.must_equal 'foo -bar ~baz ~=quux'
|
327
330
|
msg.capabilities.must_equal({
|
@@ -347,7 +350,7 @@ traffic = [
|
|
347
350
|
[
|
348
351
|
':dsfdsfdsf!~hinrik@191-108-22-46.fiber.hringdu.is MODE +i',
|
349
352
|
->(msg) {
|
350
|
-
msg.type.must_equal
|
353
|
+
msg.type.must_equal :user_mode_change
|
351
354
|
msg.mode_changes.must_equal [
|
352
355
|
{
|
353
356
|
mode: 'i',
|
@@ -359,7 +362,7 @@ traffic = [
|
|
359
362
|
[
|
360
363
|
':dsfdsfdsf!~hinrik@191-108-22-46.fiber.hringdu.is MODE #foo4321 +tlk 300 foo',
|
361
364
|
->(msg) {
|
362
|
-
msg.type.must_equal
|
365
|
+
msg.type.must_equal :channel_mode_change
|
363
366
|
msg.changer.must_equal 'dsfdsfdsf!~hinrik@191-108-22-46.fiber.hringdu.is'
|
364
367
|
msg.channel.must_equal '#foo4321'
|
365
368
|
msg.mode_changes.must_equal [
|
@@ -383,7 +386,7 @@ traffic = [
|
|
383
386
|
[
|
384
387
|
'FOO BAR :baz',
|
385
388
|
->(msg) {
|
386
|
-
msg.type.must_equal
|
389
|
+
msg.type.must_equal :foo
|
387
390
|
msg.prefix.must_equal nil
|
388
391
|
msg.args.must_equal ['BAR', 'baz']
|
389
392
|
}
|
data/test/test_coverage.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ircsupport
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,63 +9,104 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-12-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
|
16
|
-
requirement: &23821140 !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
17
|
- - ! '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
20
|
+
none: false
|
22
21
|
type: :development
|
22
|
+
name: rake
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ! '>='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
none: false
|
23
29
|
prerelease: false
|
24
|
-
version_requirements: *23821140
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
|
-
|
27
|
-
requirement: &23820680 !ruby/object:Gem::Requirement
|
28
|
-
none: false
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
29
32
|
requirements:
|
30
33
|
- - ! '>='
|
31
34
|
- !ruby/object:Gem::Version
|
32
35
|
version: '0'
|
36
|
+
none: false
|
33
37
|
type: :development
|
38
|
+
name: simplecov
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
none: false
|
34
45
|
prerelease: false
|
35
|
-
version_requirements: *23820680
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
|
-
|
38
|
-
requirement: &23820080 !ruby/object:Gem::Requirement
|
39
|
-
none: false
|
47
|
+
requirement: !ruby/object:Gem::Requirement
|
40
48
|
requirements:
|
41
49
|
- - ! '>='
|
42
50
|
- !ruby/object:Gem::Version
|
43
51
|
version: 0.7.5
|
52
|
+
none: false
|
44
53
|
type: :development
|
54
|
+
name: yard
|
55
|
+
version_requirements: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 0.7.5
|
60
|
+
none: false
|
45
61
|
prerelease: false
|
46
|
-
version_requirements: *23820080
|
47
62
|
- !ruby/object:Gem::Dependency
|
48
|
-
|
49
|
-
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ! '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
50
68
|
none: false
|
69
|
+
type: :development
|
70
|
+
name: redcarpet
|
71
|
+
version_requirements: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
none: false
|
77
|
+
prerelease: false
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
requirement: !ruby/object:Gem::Requirement
|
51
80
|
requirements:
|
52
81
|
- - ! '>='
|
53
82
|
- !ruby/object:Gem::Version
|
54
83
|
version: 2.11.4
|
84
|
+
none: false
|
55
85
|
type: :development
|
86
|
+
name: minitest
|
87
|
+
version_requirements: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ! '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: 2.11.4
|
92
|
+
none: false
|
56
93
|
prerelease: false
|
57
|
-
version_requirements: *23819520
|
58
94
|
- !ruby/object:Gem::Dependency
|
59
|
-
|
60
|
-
requirement: &23819080 !ruby/object:Gem::Requirement
|
61
|
-
none: false
|
95
|
+
requirement: !ruby/object:Gem::Requirement
|
62
96
|
requirements:
|
63
97
|
- - ! '>='
|
64
98
|
- !ruby/object:Gem::Version
|
65
99
|
version: '0'
|
100
|
+
none: false
|
66
101
|
type: :development
|
102
|
+
name: turn
|
103
|
+
version_requirements: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ! '>='
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
none: false
|
67
109
|
prerelease: false
|
68
|
-
version_requirements: *23819080
|
69
110
|
description: IRCSupport provides tools for dealing with the IRC protocol.
|
70
111
|
email:
|
71
112
|
- hinrik.sig@gmail.com
|
@@ -111,20 +152,23 @@ rdoc_options: []
|
|
111
152
|
require_paths:
|
112
153
|
- lib
|
113
154
|
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
-
none: false
|
115
155
|
requirements:
|
116
156
|
- - ! '>='
|
117
157
|
- !ruby/object:Gem::Version
|
118
|
-
version: 1.9.
|
119
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
158
|
+
version: 1.9.2
|
120
159
|
none: false
|
160
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
161
|
requirements:
|
122
162
|
- - ! '>='
|
123
163
|
- !ruby/object:Gem::Version
|
164
|
+
hash: 1831730249146677657
|
124
165
|
version: '0'
|
166
|
+
segments:
|
167
|
+
- 0
|
168
|
+
none: false
|
125
169
|
requirements: []
|
126
170
|
rubyforge_project:
|
127
|
-
rubygems_version: 1.8.
|
171
|
+
rubygems_version: 1.8.24
|
128
172
|
signing_key:
|
129
173
|
specification_version: 3
|
130
174
|
summary: An IRC protocol library
|