WildPHP / irc-bot

A simple and modular PHP IRC bot
MIT License
84 stars 24 forks source link

Hooks System #14

Closed TimTims closed 9 years ago

TimTims commented 9 years ago

Implement Hooks System.

NanoSector commented 9 years ago
<NanoSector> Setup a constructor that returns the hooks that need to be registered, then the bot registers the hooks
<NanoSector> The class can't register by itself because it's half initialised
<NanoSector> and you need to pass an instance of the class for the bot to be able to call it
<NanoSector> hmm
<NanoSector> Say a class contains function AHook, it'd return an array('the_hook_name', 'AHook');
<NanoSector> then the bot would know that it needs to hook the function AHook of class A into hook the_hook_name, and it can register it
<NanoSector> $bot->hooks->register('the_hook_name', array($class_A, 'AHook'));
<TimTims> Ok
<NanoSector> Then the hooks manager should check the given input and check if the function exists, actually register the function and keep track of it
<NanoSector> If we want to get into dynamic removing/adding of commands we have some challenges to accept as well
<NanoSector> Removing a command should not need cleaning up of hooks persay since the hook system will check if a function exists before calling it
<NanoSector> But adding a command needs to process the adding of hooks all over
Amunak commented 9 years ago

I guess we'll implement a proper event manager for modules to use.

A module should be able to:

NanoSector commented 9 years ago

The same concept as hooks I think. Variables would be passed by reference so the listeners can use them.

NanoSector commented 9 years ago

I think this is pretty much covered with the event manager in the 'new' bot, unless you have ideas that take it further?

Amunak commented 9 years ago

The basic thing is implemented, closing the issue. We can make more improvements later down the line.