Skip to content

Commit c95c063

Browse files
committed
Load codes from a text file and model them as unified objects.
Ref #214
1 parent e051a49 commit c95c063

File tree

3 files changed

+204
-180
lines changed

3 files changed

+204
-180
lines changed

irc/codes.txt

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

irc/events.py

Lines changed: 27 additions & 179 deletions
Original file line numberDiff line numberDiff line change
@@ -1,182 +1,30 @@
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}
18028

18129
codes = {v: k for k, v in numeric.items()}
18230

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ classifiers = [
1919
requires-python = ">=3.8"
2020
dependencies = [
2121
"jaraco.collections",
22-
"jaraco.text >= 3.10",
22+
"jaraco.text >= 3.14",
2323
"jaraco.logging",
2424
"jaraco.functools>=1.20",
2525
"jaraco.stream",

0 commit comments

Comments
 (0)