#include "sillybot.h"
#include "socket.h"

int main(int argc,char **argv) {
  int socket = 0x0;
  int connected = 0x0;
  char data[1024];
  printf("Start Silly Bot\n");
  while (!(socket = connectSock("irc.undernet.org",6667)));
  printf("Test: [%i]\n",socket);
  sendSock(socket,"NICK SillyBot\nUSER SillyBot 0 0 SillyBot\n");
  while (1) {
    if (readSock(socket,data)) {
      printf("%s\n",data);
      if (strstr(data,"PING")) {
        strtok(data,":");
        sendSock(socket,"PONG :%s\n",strtok(NULL,"\n"));
        connected = 1;
        }
      else if (strstr(data,"!quote")) {
        strtok(data," ");
        strtok(NULL," ");
        strtok(NULL," ");
        strtok(NULL," ");
        sendSock(socket,"%s\n",strtok(NULL,"\n"));
        }
      if (connected == 1) {
        sendSock(socket,"JOIN #UbixOS\n");
        connected = 0;
        }
      }
    }
  return(0);
  }
