This module handles event handling within girc, though users usually only interact with it via the girc.Reactor and girc.client.ServerConnection classes.
4.1. Registering events
There are several different ways to register for events in girc. You can register through the girc.Reactor, which automatically registers it on every existing and new server, or through the girc.client.ServerConnection for just that specific server.
4.1.1. girc.Reactor event registration
-
Reactor.handler(direction, verb, priority=10)
Register this function as an event handler.
| Parameters: |
- direction (str) –
in, out, both, raw.
- verb (str) – Event name.
- priority (int) – Handler priority (lower priority executes first).
|
Example
These handlers print out a pretty raw log:
reactor = girc.Reactor()
@reactor.handler('in', 'raw', priority=1)
def handle_raw_in(event):
print(event['server'].name, ' ->', escape(event['data']))
@reactor.handler('out', 'raw', priority=1)
def handle_raw_out(event):
print(event['server'].name, '<- ', escape(event['data']))
-
Reactor.register_event(direction, verb, child_fn, priority=10)
Register an event with all servers.
| Parameters: |
- direction (str) – in, out, both, raw.
- verb (str) – Event name.
- child_fn (function) – Handler function.
- priority (int) – Handler priority (lower priority executes first).
|
-
ServerConnection.register_event(direction, verb, child_fn, priority=10)
Register an event with all servers.
| Parameters: |
- direction (str) – in, out, both, or girc.
- verb (str) – Event name, all, or raw.
- child_fn (function) – Handler function.
- priority (int) – Handler priority (lower priority executes first).
|
Note: all will not match raw events. If you wish to receive both
raw and all other events, you need to register these separately.
4.2. Event directions
When registering events, you need to specify a direction to handle. These are girc’s event directions:
| Direction |
Purpose |
in |
Handle only events we receive from the server |
out |
Handle only events we send to the server |
both |
Handle both of the above |
4.3. Events
There are several standard attributes that all events share. These are:
* represents an optional attribute.
Which class source and target are depends on what we get back from the server. For some events, source and target can be a channel, a user, the server we are connected to or a different server. If source or target is us (the user we are), a girc.client.ServerConnection object will be returned instead of one of the standard types.
4.4. Raw events
In addition to the numerics below, the raw event details the exact bytes we send to and from the server. The attributes of a raw event are:
4.5. Special event attributes
Events can also have special attributes. Events that have special attributes are listed here.
4.5.1. adminemail
| Attribute |
Detail |
message |
Message text |
4.5.2. adminloc1
| Attribute |
Detail |
message |
Message text |
4.5.3. adminloc2
| Attribute |
Detail |
message |
Message text |
4.5.4. cannotsendtochan
| Attribute |
Detail |
reason |
Reason text |
channel |
girc.types.Channel object |
4.5.5. chancreatetime
| Attribute |
Detail |
timestamp |
Unix timestamp |
channel |
girc.types.Channel object |
4.5.6. cmode
| Attribute |
Detail |
target |
The target user/channel/server object |
channel |
girc.types.Channel object |
4.5.7. cmodeis
| Attribute |
Detail |
target |
The target user/channel/server object |
channel |
girc.types.Channel object |
4.5.8. ctcp
| Attribute |
Detail |
target |
The target user/channel/server object |
4.5.9. ctcp_reply
| Attribute |
Detail |
target |
The target user/channel/server object |
4.5.10. endofinfo
| Attribute |
Detail |
message |
Message text |
4.5.11. endofmotd
| Attribute |
Detail |
message |
Message text |
4.5.12. endofnames
| Attribute |
Detail |
channel |
girc.types.Channel object |
4.5.13. info
| Attribute |
Detail |
message |
Message text |
4.5.14. join
| Attribute |
Detail |
channels |
List of girc.types.Channel objects |
4.5.15. kick
| Attribute |
Detail |
message |
Message text |
user |
girc.types.User object |
4.5.16. motd
| Attribute |
Detail |
message |
Message text |
4.5.17. motdstart
| Attribute |
Detail |
message |
Message text |
4.5.18. namreply
| Attribute |
Detail |
names |
List of nicks |
channel |
girc.types.Channel object |
4.5.19. nick
| Attribute |
Detail |
new_nick |
New nickname |
4.5.20. nosuchchannel
| Attribute |
Detail |
message |
Message text |
4.5.21. nosuchnick
| Attribute |
Detail |
message |
Message text |
4.5.22. nosuchserver
| Attribute |
Detail |
message |
Message text |
4.5.23. nosuchservice
| Attribute |
Detail |
message |
Message text |
target |
The target user/channel/server object |
4.5.24. notopic
| Attribute |
Detail |
reason |
Reason text |
channel |
girc.types.Channel object |
4.5.25. part
| Attribute |
Detail |
channels |
List of girc.types.Channel objects |
4.5.26. privmsg
| Attribute |
Detail |
message |
Message text |
target |
The target user/channel/server object |
4.5.27. privnotice
| Attribute |
Detail |
message |
Message text |
target |
The target user/channel/server object |
4.5.28. pubmsg
| Attribute |
Detail |
message |
Message text |
target |
The target user/channel/server object |
channel |
girc.types.Channel object |
4.5.29. pubnotice
| Attribute |
Detail |
message |
Message text |
target |
The target user/channel/server object |
4.5.30. quit
| Attribute |
Detail |
message |
Message text |
4.5.31. targettoofast
| Attribute |
Detail |
message |
Message text |
target |
The target user/channel/server object |
4.5.32. topic
| Attribute |
Detail |
topic |
Channel topic |
channel |
girc.types.Channel object |
4.5.33. umode
| Attribute |
Detail |
target |
The target user/channel/server object |
4.5.34. welcome
| Attribute |
Detail |
message |
Message text |
nick |
Nickname |
4.5.35. yourebannedcreep
| Attribute |
Detail |
target |
The target user/channel/server object |
4.5.36. youreoper
| Attribute |
Detail |
message |
Message text |
4.6. Numerics
This is our default numeric-to-event-name mapping. Most of these originate from alien’s numeric list, which is quite out of date, so there may be insane numerics in here. This list is constantly adapting, and we prefer IRCv3 numerics over old ones.
| Numeric |
Name |
001 |
welcome |
002 |
yourhost |
003 |
created |
004 |
myinfo |
005 |
features |
008 |
snomask |
009 |
statmemtot |
010 |
bounce |
014 |
yourcookie |
042 |
yourid |
043 |
savenick |
050 |
attemptingjunc |
051 |
attemptingreroute |
200 |
tracelink |
201 |
traceconnecting |
202 |
tracehandshake |
203 |
traceunknown |
204 |
traceoperator |
205 |
traceuser |
206 |
traceserver |
207 |
traceservice |
208 |
tracenewtype |
209 |
traceclass |
210 |
stats |
211 |
statslinkinfo |
212 |
statscommands |
213 |
statscline |
215 |
statsiline |
216 |
statskline |
218 |
statsyline |
219 |
endofstats |
221 |
umode |
234 |
servlist |
235 |
servlistend |
236 |
statsverbose |
237 |
statsengine |
239 |
statsiauth |
241 |
statslline |
242 |
statsuptime |
243 |
statsoline |
244 |
statshline |
245 |
statssline |
250 |
statsconn |
251 |
luserclient |
252 |
luserop |
253 |
luserunknown |
254 |
luserchannels |
255 |
luserme |
256 |
adminme |
257 |
adminloc1 |
258 |
adminloc2 |
259 |
adminemail |
261 |
tracelog |
263 |
tryagain |
265 |
localusers |
266 |
globalusers |
267 |
start_netstat |
268 |
netstat |
269 |
end_netstat |
270 |
privs |
271 |
silelist |
272 |
endofsilelist |
273 |
notify |
276 |
vchanexist |
277 |
vchanlist |
278 |
vchanhelp |
280 |
glist |
296 |
chaninfo_kicks |
299 |
end_chaninfo |
300 |
none |
301 |
away |
302 |
userhost |
303 |
ison |
305 |
unaway |
306 |
nowaway |
311 |
whoisuser |
312 |
whoisserver |
313 |
whoisoperator |
314 |
whowasuser |
315 |
endofwho |
317 |
whoisidle |
318 |
endofwhois |
319 |
whoischannels |
320 |
whoisspecial |
322 |
list |
323 |
listend |
324 |
cmodeis |
326 |
nochanpass |
327 |
chpassunknown |
328 |
channel_url |
329 |
chancreatetime |
331 |
notopic |
332 |
topic |
333 |
topicwhotime |
339 |
badchanpass |
340 |
userip |
341 |
inviting |
345 |
invited |
346 |
invitelist |
347 |
endofinvitelist |
348 |
exceptlist |
349 |
endofexceptlist |
351 |
version |
352 |
whoreply |
353 |
namreply |
354 |
whospcrpl |
355 |
namreply_ |
364 |
links |
365 |
endoflinks |
366 |
endofnames |
367 |
banlist |
368 |
endofbanlist |
369 |
endofwhowas |
371 |
info |
372 |
motd |
374 |
endofinfo |
375 |
motdstart |
376 |
endofmotd |
381 |
youreoper |
382 |
rehashing |
383 |
youreservice |
385 |
notoperanymore |
388 |
alist |
389 |
endofalist |
391 |
time |
392 |
usersstart |
393 |
users |
394 |
endofusers |
395 |
nousers |
396 |
hosthidden |
400 |
unknownerror |
401 |
nosuchnick |
402 |
nosuchserver |
403 |
nosuchchannel |
404 |
cannotsendtochan |
405 |
toomanychannels |
406 |
wasnosuchnick |
407 |
toomanytargets |
408 |
nosuchservice |
409 |
noorigin |
410 |
invalidcapcmd |
411 |
norecipient |
412 |
notexttosend |
413 |
notoplevel |
414 |
wildtoplevel |
415 |
badmask |
416 |
querytoolong |
419 |
lengthtruncated |
421 |
unknowncommand |
422 |
nomotd |
423 |
noadmininfo |
424 |
fileerror |
425 |
noopermotd |
429 |
toomanyaway |
430 |
eventnickchange |
431 |
nonicknamegiven |
432 |
erroneusnickname |
433 |
nicknameinuse |
436 |
nickcollision |
439 |
targettoofast |
440 |
servicesdown |
441 |
usernotinchannel |
442 |
notonchannel |
443 |
useronchannel |
444 |
nologin |
445 |
summondisabled |
446 |
usersdisabled |
447 |
nonickchange |
449 |
notimplemented |
451 |
notregistered |
452 |
idcollision |
453 |
nicklost |
455 |
hostilename |
456 |
acceptfull |
457 |
acceptexist |
458 |
acceptnot |
459 |
nohiding |
460 |
notforhalfops |
461 |
needmoreparams |
462 |
alreadyregistered |
463 |
nopermforhost |
464 |
passwdmismatch |
465 |
yourebannedcreep |
467 |
keyset |
469 |
linkset |
471 |
channelisfull |
472 |
unknownmode |
473 |
inviteonlychan |
474 |
bannedfromchan |
475 |
badchannelkey |
476 |
badchanmask |
478 |
banlistfull |
479 |
linkfail |
481 |
noprivileges |
482 |
chanoprivsneeded |
483 |
cantkillserver |
485 |
uniqoprivsneeded |
488 |
tslesschan |
491 |
nooperhost |
493 |
nofeature |
494 |
badfeature |
495 |
badlogtype |
496 |
badlogsys |
497 |
badlogvalue |
498 |
isoperlchan |
499 |
chanownprivneeded |
501 |
umodeunknownflag |
502 |
usersdontmatch |
503 |
ghostedclient |
504 |
usernotonserv |
511 |
silelistfull |
512 |
toomanywatch |
513 |
badping |
515 |
badexpire |
516 |
dontcheat |
517 |
disabled |
522 |
whosyntax |
523 |
wholimexceed |
525 |
remotepfx |
526 |
pfxunroutable |
550 |
badhostmask |
551 |
hostunavail |
552 |
usingsline |
600 |
logon |
601 |
logoff |
602 |
watchoff |
603 |
watchstat |
604 |
nowon |
605 |
nowoff |
606 |
watchlist |
607 |
endofwatchlist |
608 |
watchclear |
611 |
islocop |
612 |
isnotoper |
613 |
endofisoper |
618 |
dcclist |
624 |
omotdstart |
625 |
omotd |
626 |
endofo |
630 |
settings |
631 |
endofsettings |
660 |
traceroute_hop |
661 |
traceroute_start |
662 |
modechangewarn |
663 |
chanredir |
664 |
servmodeis |
665 |
otherumodeis |
666 |
endof_generic |
670 |
starttls |
671 |
whoissecure |
672 |
unknownmodes |
673 |
cannotsetmodes |
678 |
luserstaff |
679 |
timeonserveris |
682 |
networks |
687 |
yourlanguageis |
688 |
language |
689 |
whoisstaff |
690 |
whoislanguage |
691 |
starttls_error |
702 |
modlist |
703 |
endofmodlist |
704 |
helpstart |
705 |
helptxt |
706 |
endofhelp |
708 |
etracefull |
709 |
etrace |
710 |
knock |
711 |
knockdlvr |
712 |
toomanyknock |
713 |
chanopen |
714 |
knockonchan |
715 |
knockdisabled |
716 |
targumodeg |
717 |
targnotify |
718 |
umodegmsg |
720 |
omotdstart |
721 |
omotd |
722 |
endofomotd |
723 |
noprivs |
724 |
testmark |
725 |
testline |
726 |
notestline |
730 |
mononline |
731 |
monoffline |
732 |
monlist |
733 |
endofmonlist |
734 |
monlistfull |
760 |
whoiskeyvalue |
761 |
keyvalue |
762 |
metadataend |
764 |
metadatalimit |
765 |
targetinvalid |
766 |
nomatchingkey |
767 |
keyinvalid |
768 |
keynotset |
769 |
keynopermission |
771 |
xinfo |
773 |
xinfostart |
774 |
xinfoend |
900 |
loggedin |
901 |
loggedout |
902 |
nicklocked |
903 |
saslsuccess |
904 |
saslfail |
905 |
sasltoolong |
906 |
saslaborted |
907 |
saslalready |
908 |
saslmechs |
972 |
cannotdocommand |
973 |
cannotchangeumode |
974 |
cannotchangechanmode |
975 |
cannotchangeservermode |
976 |
cannotsendtonick |
977 |
unknownservermode |
979 |
servermodelock |
980 |
badcharencoding |
981 |
toomanylanguages |
982 |
nolanguage |
983 |
texttooshort |
999 |
numeric_error |