ircbot.c  0.3.0
Multi-platform IRC bot in pure C
bot.h
Go to the documentation of this file.
1 
7 #ifndef IRCBOT_BOT_BOT_H_
8 #define IRCBOT_BOT_BOT_H_
9 struct IRC_Bot;
10 struct IRC_Connection;
11 
13 typedef int (*fp_cmd_t)(struct IRC_Bot *);
15 #define BOT_MAX_COMMANDS 128
16 
17 #define BOT_MAX_MSGLEN 512
18 
19 #define BOT_MAX_CHANNEL_LEN 64
20 
21 #define BOT_MAX_CHANNEL_AMT 128
22 
24 typedef struct Bot_Command {
26  char *name;
29 } Bot_Command;
30 
32 typedef struct IRC_Bot {
34  char *nick;
36  char **channels;
50  char last_msg[BOT_MAX_MSGLEN];
53 } IRC_Bot;
54 
61 IRC_Bot *bot_create(const char nick[]);
69 int bot_add_command(IRC_Bot *bot, const char name[], fp_cmd_t callback);
77 int bot_connect(IRC_Bot *bot, const char address[], const char port[]);
78 
84 int bot_disconnect(IRC_Bot *bot);
85 
92 int bot_call(IRC_Bot *bot, const char cmd[]);
93 
101 int bot_send(IRC_Bot *bot, const char msg[]);
102 
110 int bot_read(IRC_Bot *bot);
111 
118 int bot_join(IRC_Bot *bot, const char channel[]);
119 
126 int bot_leave(IRC_Bot *bot, const char channel[]);
127 
128 #endif // IRCBOT_BOT_BOT_H_
char port[8]
Port to be used.
Definition: connection.h:44
int bot_read(IRC_Bot *bot)
Read incoming messages from server, one message at a time.
Definition: bot.c:166
int bot_disconnect(IRC_Bot *bot)
Disconnect IRC_Bot from the server.
Definition: bot.c:130
char address[32]
Address of the server.
Definition: connection.h:39
#define BOT_MAX_COMMANDS
Maximum amount of Bot_Command structures in IRC_Bot.
Definition: bot.h:15
int(* fp_cmd_t)(struct IRC_Bot *)
Function pointer used in Bot_Command to execute custom functions.
Definition: bot.h:13
int bot_connect(IRC_Bot *bot, const char address[], const char port[])
Connect IRC_Bot to the server.
Definition: bot.c:105
int bot_call(IRC_Bot *bot, const char cmd[])
Call (execute) a Bot_Command.
Definition: bot.c:135
struct IRC_Bot IRC_Bot
Struct holding relevant data to the actual bot.
int newest_cmd
Specifies the ID of the last command added, not to be used outside of bot_ functions.
Definition: bot.h:45
struct IRC_Connection * connection
Pointer to the IRC_Connection structure.
Definition: bot.h:38
int bot_send(IRC_Bot *bot, const char msg[])
Send a text message to connected server.
Definition: bot.c:152
Struct holding relevant data to the actual bot.
Definition: bot.h:32
char * nick
Nick visible on the IRC server.
Definition: bot.h:34
char * name
Name of the command, by which it is invoked.
Definition: bot.h:26
Struct used to add custom commands to the bot.
Definition: bot.h:24
int last_channel_id
Index of the last channel joined.
Definition: bot.h:52
IRC_Connection struct holds the socket handle, receiving buffer and basic info about the connection...
Definition: connection.h:23
fp_cmd_t callback
Function pointer to the function to be executed.
Definition: bot.h:28
int bot_add_command(IRC_Bot *bot, const char name[], fp_cmd_t callback)
Add Bot_Command to the IRC_Bot.
Definition: bot.c:84
IRC_Bot * bot_create(const char nick[])
Create and populate a new IRC_Bot structure.
Definition: bot.c:55
int bot_join(IRC_Bot *bot, const char channel[])
Join an IRC channel.
Definition: bot.c:175
char ** channels
List of channels currently connected to.
Definition: bot.h:36
#define BOT_MAX_MSGLEN
Maximum length of stored message received from server.
Definition: bot.h:17
int bot_leave(IRC_Bot *bot, const char channel[])
Leave an IRC channel.
Definition: bot.c:199
struct Bot_Command Bot_Command
Struct used to add custom commands to the bot.