libircbot
library providing a framework for implementing an IRC bot
Loading...
Searching...
No Matches
IrcBot Class Reference

Static class containing the primary IRC bot API. More...

#include <ircbot/ircbot.h>

Public Member Functions

IBThreadOptsIrcBot_threadOpts (void)
 Obtain the current thread pool options for configuration. More...
 
void IrcBot_daemonize (long uid, long gid, const char *pidfile, void(*started)(void))
 Request the bot to deamonize first when running. More...
 
void IrcBot_startup (int(*startup)(void))
 Set a custom startup function. More...
 
void IrcBot_shutdown (void(*shutdown)(void))
 Set a custom shutdown function. More...
 
void IrcBot_addHandler (IrcBotEventType eventType, const char *serverId, const char *origin, const char *filter, IrcBotHandler handler)
 Register a handler for a bot event. More...
 
void IrcBot_addServer (IrcServer *server)
 Add an IRC server to be managed by the bot. More...
 
int IrcBot_run (void)
 Run the IRC bot. More...
 

Detailed Description

Static class containing the primary IRC bot API.

Member Function Documentation

◆ IrcBot_addHandler()

void IrcBot_addHandler ( IrcBotEventType  eventType,
const char *  serverId,
const char *  origin,
const char *  filter,
IrcBotHandler  handler 
)

Register a handler for a bot event.

The handler registered will be executed on a worker thread when a matching bot event occurs. It should examine the IrcBotEvent it gets passed and then configure the IrcBotResponse that can be obtained from that event.

Parameters
eventTypethe type of the event
serverIdthe id of the IrcServer, or NULL for any server
originthe channel name or the nick of the bot, or ORIGIN_CHANNEL for any channel, or ORIGIN_PRIVATE for any message received privately, or NULL for any message
filteran additional filter depending on the eventType, e.g. the command for IBET_BOTCOMMAND, or NULL for any
handlerthe handler to execute for the event

◆ IrcBot_addServer()

void IrcBot_addServer ( IrcServer server)

Add an IRC server to be managed by the bot.

Any server added will be automatically connected to. The bot will also destroy the server on shutdown.

Parameters
serverthe server

◆ IrcBot_daemonize()

void IrcBot_daemonize ( long  uid,
long  gid,
const char *  pidfile,
void(*)(void)  started 
)

Request the bot to deamonize first when running.

If a pidfile is given, it is also used to check for an already running instance.

Parameters
uidthe user id to run as, -1 to not change
gidthe group id to run as, -1 for default or no change
pidfilefull path to the pidfile to use, or NULL for none
startedcallback to run when the daemon launched successfully, or NULL

◆ IrcBot_run()

int IrcBot_run ( void  )

Run the IRC bot.

This should typically be the last function to call in your main(). It will launch a thread pool, a service loop and run the bot as previously configured, e.g. daemonize if requested and connect to all servers that were added.

Returns
the exit code

◆ IrcBot_shutdown()

void IrcBot_shutdown ( void(*)(void)  shutdown)

Set a custom shutdown function.

This function will be called during shutdown of the bot. It can for example be used to free resources that were allocated during startup.

Parameters
shutdownthe function to call on shutdown

◆ IrcBot_startup()

void IrcBot_startup ( int(*)(void)  startup)

Set a custom startup function.

This function will be run during startup of the bot. It should return EXIT_SUCCESS if everything is fine. If it returns EXIT_FAILURE, startup is aborted and the bot exits. This function is called after the bot successfully started some internal things and, if requested to do so, changed its user id.

Parameters
startupthe function to call on startup

◆ IrcBot_threadOpts()

IBThreadOpts * IrcBot_threadOpts ( void  )

Obtain the current thread pool options for configuration.

Returns
the IBThreadOpts to configure

The documentation for this class was generated from the following file: