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

Implementation of bot.h. More...

#include "bot.h"
#include "connection/connection.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

Macros

#define OK   1
 
#define ERROR   0
 
#define RECV_ERROR   -1
 

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

Implementation of bot.h.

Author
Mateusz Makowski
Date
16.09.2018

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