The IrcBot class can connect to a channel on an IRC network. Users on the same network can send messages to the bot that are parsed by message handlers. The included handlers read digital/analog inputs and write digital outputs or echo messages back to the command sender/channel. Users can write their own message handlers inheriting from the MessageHandler class to perform different actions.
Diff: IrcBot.h
- Revision:
- 2:e4c74eb20586
- Parent:
- 1:cf586c9bbb52
--- a/IrcBot.h Sat Aug 02 12:17:28 2014 +0000 +++ b/IrcBot.h Sat Aug 02 12:57:57 2014 +0000 @@ -5,27 +5,62 @@ #include "EthernetInterface.h" #include <vector> +/** + * IrcBot responds to commands on IRC using message users' handlers + */ class IrcMessage { public: + /** Create empty IrcMessage */ IrcMessage(); - IrcMessage(char *, char *, char *); + + /** Create an IrcMessage + * @param from The user sending the message. + * @param to The user/channel receiving the message. + * @param message The message. + */ + IrcMessage(char * from, char * to, char * message); char from[32], to[32], msg[256]; }; +/** + * Base MessageHandler class. + * Users should write classes inheriting from MessageHandler to parse and + * respond to incoming IRC messages. + */ class MessageHandler { public: MessageHandler() {}; virtual IrcMessage handle(IrcMessage msg) {return IrcMessage();} }; -class Irc { +/** + * IrcBot connects to an IRC network and joins a channel. Users can add message + * handlers which parse incoming private messages and respond to them. + */ +class IrcBot { public: - Irc(char *, char *, int, char *); + /** Create an IrcBot + * + * @param nickname Bot's nickname + * @param network IRC network to join + * @param port Port to connect to network on + * @param channel Channel to connect to + */ + IrcBot(char * nickname, char * network, int port, char * channel); + /** Connect to the network. + * + * Users should have already created a network interface + * (Ethernet/Wifi/3G/whatever) to carry the connection. + */ void connect(); + /// Disconnect from the network. void disconnect(); + /// Add a handler for incoming messages. void add(MessageHandler *); - void identify(char *); - void join(char *); + + /** Read data from internet connection, parse input and handle any + * incoming private messages + */ bool read(); private: void handle(IrcMessage);