Skip to content

Commit

Permalink
Load codes from a text file and model them as unified objects.
Browse files Browse the repository at this point in the history
Ref #214
  • Loading branch information
jaraco committed Jul 14, 2024
1 parent e051a49 commit c95c063
Show file tree
Hide file tree
Showing 3 changed files with 204 additions and 180 deletions.
176 changes: 176 additions & 0 deletions irc/codes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
001 welcome
002 yourhost
003 created
004 myinfo
005 featurelist # XXX
200 tracelink
201 traceconnecting
202 tracehandshake
203 traceunknown
204 traceoperator
205 traceuser
206 traceserver
207 traceservice
208 tracenewtype
209 traceclass
210 tracereconnect
211 statslinkinfo
212 statscommands
213 statscline
214 statsnline
215 statsiline
216 statskline
217 statsqline
218 statsyline
219 endofstats
221 umodeis
231 serviceinfo
232 endofservices
233 service
234 servlist
235 servlistend
241 statslline
242 statsuptime
243 statsoline
244 statshline
250 luserconns
251 luserclient
252 luserop
253 luserunknown
254 luserchannels
255 luserme
256 adminme
257 adminloc1
258 adminloc2
259 adminemail
261 tracelog
262 endoftrace
263 tryagain
265 n_local
266 n_global
300 none
301 away
302 userhost
303 ison
305 unaway
306 nowaway
311 whoisuser
312 whoisserver
313 whoisoperator
314 whowasuser
315 endofwho
316 whoischanop
317 whoisidle
318 endofwhois
319 whoischannels
321 liststart
322 list
323 listend
324 channelmodeis
329 channelcreate
# <nick> <accountName> :<info> - Spawned from a /whois
330 whoisaccount
331 notopic
332 currenttopic
333 topicinfo
341 inviting
342 summoning
346 invitelist
347 endofinvitelist
348 exceptlist
349 endofexceptlist
351 version
352 whoreply
353 namreply
# Response to a WHOX query
354 whospcrpl
361 killdone
362 closing
363 closeend
364 links
365 endoflinks
366 endofnames
367 banlist
368 endofbanlist
369 endofwhowas
371 info
372 motd
373 infostart
374 endofinfo
375 motdstart
376 endofmotd
377 motd2
381 youreoper
382 rehashing
384 myportis
391 time
392 usersstart
393 users
394 endofusers
395 nousers
401 nosuchnick
402 nosuchserver
403 nosuchchannel
404 cannotsendtochan
405 toomanychannels
406 wasnosuchnick
407 toomanytargets
409 noorigin
410 invalidcapcmd
411 norecipient
412 notexttosend
413 notoplevel
414 wildtoplevel
421 unknowncommand
422 nomotd
423 noadmininfo
424 fileerror
431 nonicknamegiven
432 erroneusnickname # Thiss iz how its speld in thee RFC.
433 nicknameinuse
436 nickcollision
437 unavailresource # "Nick temporally unavailable"
441 usernotinchannel
442 notonchannel
443 useronchannel
444 nologin
445 summondisabled
446 usersdisabled
451 notregistered
461 needmoreparams
462 alreadyregistered
463 nopermforhost
464 passwdmismatch
465 yourebannedcreep # I love this one...
466 youwillbebanned
467 keyset
471 channelisfull
472 unknownmode
473 inviteonlychan
474 bannedfromchan
475 badchannelkey
476 badchanmask
477 nochanmodes # "Channel doesn't support modes"
478 banlistfull
# generated when /knock <chan> is ran on a channel that you
# are either in or has /knock'ing disabled
480 cannotknock
481 noprivileges
482 chanoprivsneeded
483 cantkillserver
484 restricted # Connection is restricted
485 uniqopprivsneeded
491 nooperhost
492 noservicehost
501 umodeunknownflag
502 usersdontmatch
# IRCv3.1 SASL https://ircv3.net/specs/extensions/sasl-3.1
900 loggedin
901 loggedout
902 nicklocked
903 saslsuccess
904 saslfail
905 sasltoolong
906 saslaborted
907 saslalready
908 saslmechs
206 changes: 27 additions & 179 deletions irc/events.py
Original file line number Diff line number Diff line change
@@ -1,182 +1,30 @@
# Numeric table based on the Perl's Net::IRC.
numeric = {
"001": "welcome",
"002": "yourhost",
"003": "created",
"004": "myinfo",
"005": "featurelist", # XXX
"200": "tracelink",
"201": "traceconnecting",
"202": "tracehandshake",
"203": "traceunknown",
"204": "traceoperator",
"205": "traceuser",
"206": "traceserver",
"207": "traceservice",
"208": "tracenewtype",
"209": "traceclass",
"210": "tracereconnect",
"211": "statslinkinfo",
"212": "statscommands",
"213": "statscline",
"214": "statsnline",
"215": "statsiline",
"216": "statskline",
"217": "statsqline",
"218": "statsyline",
"219": "endofstats",
"221": "umodeis",
"231": "serviceinfo",
"232": "endofservices",
"233": "service",
"234": "servlist",
"235": "servlistend",
"241": "statslline",
"242": "statsuptime",
"243": "statsoline",
"244": "statshline",
"250": "luserconns",
"251": "luserclient",
"252": "luserop",
"253": "luserunknown",
"254": "luserchannels",
"255": "luserme",
"256": "adminme",
"257": "adminloc1",
"258": "adminloc2",
"259": "adminemail",
"261": "tracelog",
"262": "endoftrace",
"263": "tryagain",
"265": "n_local",
"266": "n_global",
"300": "none",
"301": "away",
"302": "userhost",
"303": "ison",
"305": "unaway",
"306": "nowaway",
"311": "whoisuser",
"312": "whoisserver",
"313": "whoisoperator",
"314": "whowasuser",
"315": "endofwho",
"316": "whoischanop",
"317": "whoisidle",
"318": "endofwhois",
"319": "whoischannels",
"321": "liststart",
"322": "list",
"323": "listend",
"324": "channelmodeis",
"329": "channelcreate",
# <nick> <accountName> :<info> - Spawned from a /whois
"330": "whoisaccount",
"331": "notopic",
"332": "currenttopic",
"333": "topicinfo",
"341": "inviting",
"342": "summoning",
"346": "invitelist",
"347": "endofinvitelist",
"348": "exceptlist",
"349": "endofexceptlist",
"351": "version",
"352": "whoreply",
"353": "namreply",
# Response to a WHOX query
"354": "whospcrpl",
"361": "killdone",
"362": "closing",
"363": "closeend",
"364": "links",
"365": "endoflinks",
"366": "endofnames",
"367": "banlist",
"368": "endofbanlist",
"369": "endofwhowas",
"371": "info",
"372": "motd",
"373": "infostart",
"374": "endofinfo",
"375": "motdstart",
"376": "endofmotd",
"377": "motd2",
"381": "youreoper",
"382": "rehashing",
"384": "myportis",
"391": "time",
"392": "usersstart",
"393": "users",
"394": "endofusers",
"395": "nousers",
"401": "nosuchnick",
"402": "nosuchserver",
"403": "nosuchchannel",
"404": "cannotsendtochan",
"405": "toomanychannels",
"406": "wasnosuchnick",
"407": "toomanytargets",
"409": "noorigin",
"410": "invalidcapcmd",
"411": "norecipient",
"412": "notexttosend",
"413": "notoplevel",
"414": "wildtoplevel",
"421": "unknowncommand",
"422": "nomotd",
"423": "noadmininfo",
"424": "fileerror",
"431": "nonicknamegiven",
"432": "erroneusnickname", # Thiss iz how its speld in thee RFC.
"433": "nicknameinuse",
"436": "nickcollision",
"437": "unavailresource", # "Nick temporally unavailable"
"441": "usernotinchannel",
"442": "notonchannel",
"443": "useronchannel",
"444": "nologin",
"445": "summondisabled",
"446": "usersdisabled",
"451": "notregistered",
"461": "needmoreparams",
"462": "alreadyregistered",
"463": "nopermforhost",
"464": "passwdmismatch",
"465": "yourebannedcreep", # I love this one...
"466": "youwillbebanned",
"467": "keyset",
"471": "channelisfull",
"472": "unknownmode",
"473": "inviteonlychan",
"474": "bannedfromchan",
"475": "badchannelkey",
"476": "badchanmask",
"477": "nochanmodes", # "Channel doesn't support modes"
"478": "banlistfull",
# generated when /knock <chan> is ran on a channel that you
# are either in or has /knock'ing disabled
"480": "cannotknock",
"481": "noprivileges",
"482": "chanoprivsneeded",
"483": "cantkillserver",
"484": "restricted", # Connection is restricted
"485": "uniqopprivsneeded",
"491": "nooperhost",
"492": "noservicehost",
"501": "umodeunknownflag",
"502": "usersdontmatch",
# IRCv3.1 SASL https://ircv3.net/specs/extensions/sasl-3.1
"900": "loggedin",
"901": "loggedout",
"902": "nicklocked",
"903": "saslsuccess",
"904": "saslfail",
"905": "sasltoolong",
"906": "saslaborted",
"907": "saslalready",
"908": "saslmechs",
}
import itertools
from importlib.resources import files

from jaraco.text import clean, drop_comment, lines_from


class Code(str):
def __new__(cls, code, name):
return super().__new__(cls, name)

def __init__(self, code, name):
self.code = code

def __int__(self):
return int(self.code)


_codes = itertools.starmap(
Code,
map(
str.split,
map(drop_comment, clean(lines_from(files().joinpath('codes.txt')))),
),
)


numeric = {code.code: code for code in _codes}

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

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ classifiers = [
requires-python = ">=3.8"
dependencies = [
"jaraco.collections",
"jaraco.text >= 3.10",
"jaraco.text >= 3.14",
"jaraco.logging",
"jaraco.functools>=1.20",
"jaraco.stream",
Expand Down

0 comments on commit c95c063

Please sign in to comment.