This repository has been archived by the owner on Apr 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 180
/
isupport.rb
98 lines (90 loc) · 2.79 KB
/
isupport.rb
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
86
87
88
89
90
91
92
93
94
95
96
97
98
module Cinch
# This class exposes parsed ISUPPORT information of the IRC network.
class ISupport < Hash
@@mappings = {
%w[PREFIX] => lambda {|v|
modes, prefixes = v.match(/^\((.+)\)(.+)$/)[1..2]
h = {}
modes.split("").each_with_index do |c, i|
h[c] = prefixes[i]
end
h
},
%w[CHANTYPES] => lambda {|v| v.split("")},
%w[CHANMODES] => lambda {|v|
h = {}
h["A"], h["B"], h["C"], h["D"] = v.split(",").map {|l| l.split("")}
h
},
%w[MODES MAXCHANNELS NICKLEN MAXBANS TOPICLEN
KICKLEN CHANNELLEN CHIDLEN SILENCE AWAYLEN
MAXTARGETS WATCH MONITOR] => lambda {|v| v.to_i},
%w[CHANLIMIT MAXLIST IDCHAN] => lambda {|v|
h = {}
v.split(",").each do |pair|
args, num = pair.split(":")
args.split("").each do |arg|
h[arg] = num.to_i
end
end
h
},
%w[TARGMAX] => lambda {|v|
h = {}
v.split(",").each do |pair|
name, value = pair.split(":")
h[name] = value.to_i
end
h
},
%w[NETWORK] => lambda {|v| v},
%w[STATUSMSG] => lambda {|v| v.split("")},
%w[CASEMAPPING] => lambda {|v| v.to_sym},
%w[ELIST] => lambda {|v| v.split("")},
# TODO STD
}
def initialize(*args)
super
# by setting most numeric values to "Infinity", we let the
# server truncate messages and lists while at the same time
# allowing the use of strictness=:strict for servers that don't
# support ISUPPORT (hopefully none, anyway)
self["PREFIX"] = {"o" => "@", "v" => "+"}
self["CHANTYPES"] = ["#"]
self["CHANMODES"] = {
"A" => ["b"],
"B" => ["k"],
"C" => ["l"],
"D" => %w[i m n p s t r]
}
self["MODES"] = 1
self["NICKLEN"] = Float::INFINITY
self["MAXBANS"] = Float::INFINITY
self["TOPICLEN"] = Float::INFINITY
self["KICKLEN"] = Float::INFINITY
self["CHANNELLEN"] = Float::INFINITY
self["CHIDLEN"] = 5
self["AWAYLEN"] = Float::INFINITY
self["MAXTARGETS"] = 1
self["MAXCHANNELS"] = Float::INFINITY # deprecated
self["CHANLIMIT"] = {"#" => Float::INFINITY}
self["STATUSMSG"] = []
self["CASEMAPPING"] = :rfc1459
self["ELIST"] = []
self["MONITOR"] = 0
end
# @api private
# @return [void]
def parse(*options)
options.each do |option|
name, value = option.split("=")
if value
proc = @@mappings.find {|key, _| key.include?(name)}
self[name] = (proc && proc[1].call(value)) || value
else
self[name] = true
end
end
end
end
end