Modules:QuickList:InternalEvents
From Anope Wiki
Contents |
Internal Events
Internal Events allow you to hook to internal events happening in Anope. More information about events can be found in docs/EVENTS in the Anope directory.
createEventHook
Creates an event handler for internal events.
EvtHook *createEventHook(char *name, int (*func) (int argc, char **argv))
Hook to the internal event named name (refer to Modules:Misc:InternalEventList for a complete list of available events), and call the function func when such an event is being emitted.
Returns a pointer to the EvtHook struct which contains information about the event.
moduleAddEventHook
Hook an EvtHook struct to the event list.
int moduleAddEventHook(EvtHook *evh)
Inserts the given evh (pointer to EvtHook struct created with createEventHook) into the event list. This should be done for any created EvtHook.
Returns:
- MOD_ERR_OK - Success
- MOD_ERR_PARAMS - A NULL-pointer was passed
- MOD_ERR_UNKNOWN - Anope doesn't know which module called the function
moduleEventDelHook
Delete a hooked internal event handler.
int moduleEventDelHook(const char *name)
Deletes the event handler hooked to the internal event of type name from the event list. This also performs all cleanups required.
Returns:
- MOD_ERR_OK - Success
- MOD_ERR_UNKNOWN - Anope doesn't know which module called the function
- MOD_ERR_NOEXIST - There is no hook for the given name
Example
#include <module.h>
int my_save(int ac, char **av)
int AnopeInit(int argc, char **argv)
{
EvtHook *hook;
hook = createEventHook(EVENT_DB_SAVING, my_save);
if (moduleAddEventHook(hook) != MOD_ERR_OK) {
alog("Can't hook to EVENT_DB_SAVING event");
return MOD_STOP;
}
return MOD_CONT;
}
int my_save(int ac, char **av)
{
if (ac < 1)
return MOD_CONT;
if (stricmp(av[0], EVENT_START) == 0)
alog("Saving databases...");
else
alog("Completed saving databases!");
if (moduleEventDelHook(EVENT_DB_SAVING) == MOD_ERR_OK)
alog("Succesfully deleted event hook for EVENT_DB_SAVING");
else
alog("Unable to delete event hook for EVENT_DB_SAVING");
return MOD_CONT;
}

