gnulag / circ

#gnulag's IRC bot
BSD 2-Clause "Simplified" License
3 stars 3 forks source link

Implement IRC hooks and move most code to it #16

Closed colfrog closed 5 years ago

colfrog commented 5 years ago

This is done through a global GHashTable to hook commands to a linked list of functions to call. A special PREINIT command used to allow for executing functions before registering the client. However, since client registration is done in PREINIT, it has to be the last element in the linked list. This is only done by hooking it after every other PREINIT hook. exec_hooks runs PREINIT hooks when msg is NULL, it runs "" hooks when msg is 1, else it grabs the command from the message and runs all hooks for that command. "\" hooks run for every single message. This is to allow something like an module engine to run its own hooks interface.

This allowed a lot of code to be moved from main and the callback to a file containing core hooks. It also makes irc_init_loop_callback unnecessary.

We can use this to start developing modules in C, although the plan is to use a scheme interpreter and to provide it with an API for developing modules.