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.

Revision:
2:e4c74eb20586
Parent:
1:cf586c9bbb52
--- a/IrcBot.cpp	Sat Aug 02 12:17:28 2014 +0000
+++ b/IrcBot.cpp	Sat Aug 02 12:57:57 2014 +0000
@@ -12,7 +12,7 @@
     msg[0] = '\0';
 }
 
-Irc::Irc(char * nick, char * net, int p, char * chan) :
+IrcBot::IrcBot(char * nick, char * net, int p, char * chan) :
         pc(USBTX, USBRX), sock(), port(p), ident(false), connected(false),
         setup(false), joined(false), parseindex(0)
 {
@@ -20,28 +20,17 @@
     sprintf(password, "%s", "");
     sprintf(network, "%s", net);
     sprintf(channel, "%s", chan);
-    pc.printf("Created Irc obj for %s.\n", nickname);
-}
-
-void Irc::identify(char * pass) {
-    ident = true;
-    sprintf(password, "%s", pass);    
+    pc.printf("Created IrcBot obj for %s.\n", nickname);
 }
 
-void Irc::join(char * chan) {
-    char cmd[64];
-    sprintf(cmd, ":source JOIN :%s\r\n", chan);
-    send(cmd);
-}
-
-void Irc::connect() {
+void IrcBot::connect() {
     pc.printf("Connecting to %s:%d...\n", network, port);
     sock.connect(network, port);
     pc.printf("Done.\n");
     connected = true;
 }
 
-void Irc::disconnect() {
+void IrcBot::disconnect() {
     if (connected) {
         pc.printf("Disconnecting.\n");
         sock.close();
@@ -49,11 +38,11 @@
     }
 }
 
-void Irc::add(MessageHandler * handler) {
+void IrcBot::add(MessageHandler * handler) {
     handlers.push_back(handler);
 }
 
-bool Irc::read() {
+bool IrcBot::read() {
     if (!connected) return 0;
     int ret = sock.receive(readbuffer, sizeof(readbuffer) - 1);
     bool parsed = false;
@@ -74,7 +63,7 @@
     return parsed;
 }
 
-void Irc::send(char * cmd) {
+void IrcBot::send(char * cmd) {
     if (!connected) return;
     int i = 0;
     bool ok = true;
@@ -90,7 +79,7 @@
     sock.send_all(cmd, i);
 }
 
-void Irc::handle(IrcMessage msg) {
+void IrcBot::handle(IrcMessage msg) {
     pc.printf("Handling message from %s, to %s: %s\n", msg.from, msg.to, msg.msg);    
     for (int i = 0; i < handlers.size(); i++) {
         IrcMessage out = handlers.at(i)->handle(msg);
@@ -104,7 +93,7 @@
     }
 }
 
-void Irc::parse() {
+void IrcBot::parse() {
     pc.printf("Parsing: --%s--\n", parsebuffer);
     if (setup && (!joined)) {
         char cmd[256];