ircbot.c  0.3.0
Multi-platform IRC bot in pure C
bot.h File Reference

File containing the bot data structure and related functions. More...

Go to the source code of this file.

Data Structures

struct  Bot_Command
 Struct used to add custom commands to the bot. More...
 
struct  IRC_Bot
 Struct holding relevant data to the actual bot. More...
 

Macros

#define BOT_MAX_COMMANDS   128
 Maximum amount of Bot_Command structures in IRC_Bot. More...
 
#define BOT_MAX_MSGLEN   512
 Maximum length of stored message received from server. More...
 
#define BOT_MAX_CHANNEL_LEN   64
 Max characters in channel name. More...
 
#define BOT_MAX_CHANNEL_AMT   128
 Max channels the bot can join. More...
 

Typedefs

typedef int(* fp_cmd_t) (struct IRC_Bot *)
 Function pointer used in Bot_Command to execute custom functions. More...
 
typedef struct Bot_Command Bot_Command
 Struct used to add custom commands to the bot. More...
 
typedef struct IRC_Bot IRC_Bot
 Struct holding relevant data to the actual bot. More...
 

Functions

IRC_Botbot_create (const char nick[])
 Create and populate a new IRC_Bot structure. More...
 
int bot_add_command (IRC_Bot *bot, const char name[], fp_cmd_t callback)
 Add Bot_Command to the IRC_Bot. More...
 
int bot_connect (IRC_Bot *bot, const char address[], const char port[])
 Connect IRC_Bot to the server. More...
 
int bot_disconnect (IRC_Bot *bot)
 Disconnect IRC_Bot from the server. More...
 
int bot_call (IRC_Bot *bot, const char cmd[])
 Call (execute) a Bot_Command. More...
 
int bot_send (IRC_Bot *bot, const char msg[])
 Send a text message to connected server. More...
 
int bot_read (IRC_Bot *bot)
 Read incoming messages from server, one message at a time. More...
 
int bot_join (IRC_Bot *bot, const char channel[])
 Join an IRC channel. More...
 
int bot_leave (IRC_Bot *bot, const char channel[])
 Leave an IRC channel. More...
 

Detailed Description

File containing the bot data structure and related functions.

Author
Mateusz Makowski
Date
15.09.2018

Macro Definition Documentation

◆ BOT_MAX_CHANNEL_AMT

#define BOT_MAX_CHANNEL_AMT   128

Max channels the bot can join.

◆ BOT_MAX_CHANNEL_LEN

#define BOT_MAX_CHANNEL_LEN   64

Max characters in channel name.

◆ BOT_MAX_COMMANDS

#define BOT_MAX_COMMANDS   128

Maximum amount of Bot_Command structures in IRC_Bot.

◆ BOT_MAX_MSGLEN

#define BOT_MAX_MSGLEN   512

Maximum length of stored message received from server.

Typedef Documentation

◆ Bot_Command

typedef struct Bot_Command Bot_Command

Struct used to add custom commands to the bot.

◆ fp_cmd_t

typedef int(* fp_cmd_t) (struct IRC_Bot *)

Function pointer used in Bot_Command to execute custom functions.

◆ IRC_Bot

typedef struct IRC_Bot IRC_Bot

Struct holding relevant data to the actual bot.

Function Documentation

◆ bot_add_command()

int bot_add_command ( IRC_Bot bot,
const char  name[],
fp_cmd_t  callback 
)

Add Bot_Command to the IRC_Bot.

Parameters
botpointer to IRC_Bot object
namecommand name
callbackfunction pointer to be called when executing this command
Returns
0 on failure, 1 on success

◆ bot_call()

int bot_call ( IRC_Bot bot,
const char  cmd[] 
)

Call (execute) a Bot_Command.

Parameters
botpointer to IRC_Bot object
cmdcommand name to be called
Returns
0 on failure, 1 on success

◆ bot_connect()

int bot_connect ( IRC_Bot bot,
const char  address[],
const char  port[] 
)

Connect IRC_Bot to the server.

Parameters
botpointer to IRC_Bot object
addressIRC server address to connect to
portIRC port number (as a string)
Returns
0 on failure, 1 on success

◆ bot_create()

IRC_Bot* bot_create ( const char  nick[])

Create and populate a new IRC_Bot structure.

Parameters
nickvisible nickname on the IRC server
Returns
pointer to the newly created IRC_Bot object or null pointer on failure

◆ bot_disconnect()

int bot_disconnect ( IRC_Bot bot)

Disconnect IRC_Bot from the server.

Parameters
botpointer to IRC_Bot object
Returns
0 on failure, 1 on success

◆ bot_join()

int bot_join ( IRC_Bot bot,
const char  channel[] 
)

Join an IRC channel.

Parameters
botpointer to IRC_Bot object
channelchannel to join
Returns
0 on failure, 1 on success

◆ bot_leave()

int bot_leave ( IRC_Bot bot,
const char  channel[] 
)

Leave an IRC channel.

Parameters
botpointer to IRC_Bot object
channelchannel to leave
Returns
0 on failure, 1 on success

◆ bot_read()

int bot_read ( IRC_Bot bot)

Read incoming messages from server, one message at a time.

Parameters
botpointer to IRC_Bot object
Returns
negative numbers on socket errors, 0 - connection closed, positive numbers denote bytes read
See also
last_msg

◆ bot_send()

int bot_send ( IRC_Bot bot,
const char  msg[] 
)

Send a text message to connected server.

Parameters
botpointer to IRC_Bot object
msgmessage string to be sent (doesn't have to include trailing newline)
Returns
0 on failure, 1 on success