/usr/lib/ruby/vendor_ruby/net/irc/message/modeparser.rb is in ruby-net-irc 0.0.9-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | class Net::IRC::Message::ModeParser
ONE_PARAM_MASK = 0
ONE_PARAM = 1
ONE_PARAM_FOR_POSITIVE = 2
NO_PARAM = 3
def initialize
@modes = {}
@op_to_mark_map = {}
@mark_to_op_map = {}
# Initialize for ircd 2.11 (RFC2812+)
set(:CHANMODES, 'beIR,k,l,imnpstaqr')
set(:PREFIX, '(ov)@+')
end
def mark_to_op(mark)
mark.empty? ? nil : @mark_to_op_map[mark.to_sym]
end
def set(key, value)
case key
when :PREFIX
if value =~ /\A\(([a-zA-Z]+)\)(.+)\z/
@op_to_mark_map = {}
key, value = Regexp.last_match[1], Regexp.last_match[2]
key.scan(/./).zip(value.scan(/./)) {|pair|
@op_to_mark_map[pair[0].to_sym] = pair[1].to_sym
}
@mark_to_op_map = @op_to_mark_map.invert
end
when :CHANMODES
@modes = {}
value.split(",").each_with_index do |s, kind|
s.scan(/./).each {|c|
@modes[c.to_sym] = kind
}
end
end
end
def parse(arg)
params = arg.kind_of?(Net::IRC::Message) ? arg.to_a : arg.split(" ")
params.shift
ret = {
:positive => [],
:negative => [],
}
current = ret[:positive]
until params.empty?
s = params.shift
s.scan(/./).each do |c|
c = c.to_sym
case c
when :+
current = ret[:positive]
when :-
current = ret[:negative]
else
case @modes[c]
when ONE_PARAM_MASK,ONE_PARAM
current << [c, params.shift]
when ONE_PARAM_FOR_POSITIVE
if current.equal?(ret[:positive])
current << [c, params.shift]
else
current << [c, nil]
end
when NO_PARAM
current << [c, nil]
else
if @op_to_mark_map[c]
current << [c, params.shift]
end
end
end
end
end
ret
end
end
|