|
1 | | -# Numeric table based on the Perl's Net::IRC. |
2 | | -numeric = { |
3 | | - "001": "welcome", |
4 | | - "002": "yourhost", |
5 | | - "003": "created", |
6 | | - "004": "myinfo", |
7 | | - "005": "featurelist", # XXX |
8 | | - "200": "tracelink", |
9 | | - "201": "traceconnecting", |
10 | | - "202": "tracehandshake", |
11 | | - "203": "traceunknown", |
12 | | - "204": "traceoperator", |
13 | | - "205": "traceuser", |
14 | | - "206": "traceserver", |
15 | | - "207": "traceservice", |
16 | | - "208": "tracenewtype", |
17 | | - "209": "traceclass", |
18 | | - "210": "tracereconnect", |
19 | | - "211": "statslinkinfo", |
20 | | - "212": "statscommands", |
21 | | - "213": "statscline", |
22 | | - "214": "statsnline", |
23 | | - "215": "statsiline", |
24 | | - "216": "statskline", |
25 | | - "217": "statsqline", |
26 | | - "218": "statsyline", |
27 | | - "219": "endofstats", |
28 | | - "221": "umodeis", |
29 | | - "231": "serviceinfo", |
30 | | - "232": "endofservices", |
31 | | - "233": "service", |
32 | | - "234": "servlist", |
33 | | - "235": "servlistend", |
34 | | - "241": "statslline", |
35 | | - "242": "statsuptime", |
36 | | - "243": "statsoline", |
37 | | - "244": "statshline", |
38 | | - "250": "luserconns", |
39 | | - "251": "luserclient", |
40 | | - "252": "luserop", |
41 | | - "253": "luserunknown", |
42 | | - "254": "luserchannels", |
43 | | - "255": "luserme", |
44 | | - "256": "adminme", |
45 | | - "257": "adminloc1", |
46 | | - "258": "adminloc2", |
47 | | - "259": "adminemail", |
48 | | - "261": "tracelog", |
49 | | - "262": "endoftrace", |
50 | | - "263": "tryagain", |
51 | | - "265": "n_local", |
52 | | - "266": "n_global", |
53 | | - "300": "none", |
54 | | - "301": "away", |
55 | | - "302": "userhost", |
56 | | - "303": "ison", |
57 | | - "305": "unaway", |
58 | | - "306": "nowaway", |
59 | | - "311": "whoisuser", |
60 | | - "312": "whoisserver", |
61 | | - "313": "whoisoperator", |
62 | | - "314": "whowasuser", |
63 | | - "315": "endofwho", |
64 | | - "316": "whoischanop", |
65 | | - "317": "whoisidle", |
66 | | - "318": "endofwhois", |
67 | | - "319": "whoischannels", |
68 | | - "321": "liststart", |
69 | | - "322": "list", |
70 | | - "323": "listend", |
71 | | - "324": "channelmodeis", |
72 | | - "329": "channelcreate", |
73 | | - # <nick> <accountName> :<info> - Spawned from a /whois |
74 | | - "330": "whoisaccount", |
75 | | - "331": "notopic", |
76 | | - "332": "currenttopic", |
77 | | - "333": "topicinfo", |
78 | | - "341": "inviting", |
79 | | - "342": "summoning", |
80 | | - "346": "invitelist", |
81 | | - "347": "endofinvitelist", |
82 | | - "348": "exceptlist", |
83 | | - "349": "endofexceptlist", |
84 | | - "351": "version", |
85 | | - "352": "whoreply", |
86 | | - "353": "namreply", |
87 | | - # Response to a WHOX query |
88 | | - "354": "whospcrpl", |
89 | | - "361": "killdone", |
90 | | - "362": "closing", |
91 | | - "363": "closeend", |
92 | | - "364": "links", |
93 | | - "365": "endoflinks", |
94 | | - "366": "endofnames", |
95 | | - "367": "banlist", |
96 | | - "368": "endofbanlist", |
97 | | - "369": "endofwhowas", |
98 | | - "371": "info", |
99 | | - "372": "motd", |
100 | | - "373": "infostart", |
101 | | - "374": "endofinfo", |
102 | | - "375": "motdstart", |
103 | | - "376": "endofmotd", |
104 | | - "377": "motd2", |
105 | | - "381": "youreoper", |
106 | | - "382": "rehashing", |
107 | | - "384": "myportis", |
108 | | - "391": "time", |
109 | | - "392": "usersstart", |
110 | | - "393": "users", |
111 | | - "394": "endofusers", |
112 | | - "395": "nousers", |
113 | | - "401": "nosuchnick", |
114 | | - "402": "nosuchserver", |
115 | | - "403": "nosuchchannel", |
116 | | - "404": "cannotsendtochan", |
117 | | - "405": "toomanychannels", |
118 | | - "406": "wasnosuchnick", |
119 | | - "407": "toomanytargets", |
120 | | - "409": "noorigin", |
121 | | - "410": "invalidcapcmd", |
122 | | - "411": "norecipient", |
123 | | - "412": "notexttosend", |
124 | | - "413": "notoplevel", |
125 | | - "414": "wildtoplevel", |
126 | | - "421": "unknowncommand", |
127 | | - "422": "nomotd", |
128 | | - "423": "noadmininfo", |
129 | | - "424": "fileerror", |
130 | | - "431": "nonicknamegiven", |
131 | | - "432": "erroneusnickname", # Thiss iz how its speld in thee RFC. |
132 | | - "433": "nicknameinuse", |
133 | | - "436": "nickcollision", |
134 | | - "437": "unavailresource", # "Nick temporally unavailable" |
135 | | - "441": "usernotinchannel", |
136 | | - "442": "notonchannel", |
137 | | - "443": "useronchannel", |
138 | | - "444": "nologin", |
139 | | - "445": "summondisabled", |
140 | | - "446": "usersdisabled", |
141 | | - "451": "notregistered", |
142 | | - "461": "needmoreparams", |
143 | | - "462": "alreadyregistered", |
144 | | - "463": "nopermforhost", |
145 | | - "464": "passwdmismatch", |
146 | | - "465": "yourebannedcreep", # I love this one... |
147 | | - "466": "youwillbebanned", |
148 | | - "467": "keyset", |
149 | | - "471": "channelisfull", |
150 | | - "472": "unknownmode", |
151 | | - "473": "inviteonlychan", |
152 | | - "474": "bannedfromchan", |
153 | | - "475": "badchannelkey", |
154 | | - "476": "badchanmask", |
155 | | - "477": "nochanmodes", # "Channel doesn't support modes" |
156 | | - "478": "banlistfull", |
157 | | - # generated when /knock <chan> is ran on a channel that you |
158 | | - # are either in or has /knock'ing disabled |
159 | | - "480": "cannotknock", |
160 | | - "481": "noprivileges", |
161 | | - "482": "chanoprivsneeded", |
162 | | - "483": "cantkillserver", |
163 | | - "484": "restricted", # Connection is restricted |
164 | | - "485": "uniqopprivsneeded", |
165 | | - "491": "nooperhost", |
166 | | - "492": "noservicehost", |
167 | | - "501": "umodeunknownflag", |
168 | | - "502": "usersdontmatch", |
169 | | - # IRCv3.1 SASL https://ircv3.net/specs/extensions/sasl-3.1 |
170 | | - "900": "loggedin", |
171 | | - "901": "loggedout", |
172 | | - "902": "nicklocked", |
173 | | - "903": "saslsuccess", |
174 | | - "904": "saslfail", |
175 | | - "905": "sasltoolong", |
176 | | - "906": "saslaborted", |
177 | | - "907": "saslalready", |
178 | | - "908": "saslmechs", |
179 | | -} |
| 1 | +import itertools |
| 2 | +from importlib.resources import files |
| 3 | + |
| 4 | +from jaraco.text import clean, drop_comment, lines_from |
| 5 | + |
| 6 | + |
| 7 | +class Code(str): |
| 8 | + def __new__(cls, code, name): |
| 9 | + return super().__new__(cls, name) |
| 10 | + |
| 11 | + def __init__(self, code, name): |
| 12 | + self.code = code |
| 13 | + |
| 14 | + def __int__(self): |
| 15 | + return int(self.code) |
| 16 | + |
| 17 | + |
| 18 | +_codes = itertools.starmap( |
| 19 | + Code, |
| 20 | + map( |
| 21 | + str.split, |
| 22 | + map(drop_comment, clean(lines_from(files().joinpath('codes.txt')))), |
| 23 | + ), |
| 24 | +) |
| 25 | + |
| 26 | + |
| 27 | +numeric = {code.code: code for code in _codes} |
180 | 28 |
|
181 | 29 | codes = {v: k for k, v in numeric.items()} |
182 | 30 |
|
|
0 commit comments