Newer
Older
Scratch / aibot / src / main.c
@Christopher W. Olsen Christopher W. Olsen on 25 Oct 2019 1022 bytes Scratch
#include "aibot.h"
#include "socket.h"
#include "irc.h"

int main(int argc,char *argv[]) {
  int s;
  char *output;
  IRC irc;
  irc = (IRC) malloc (sizeof(IRCNode));
  printf("Starting AI Bot\n");
  irc->socket = Connect("irc.undernet.org",6667);
  printf("Test: [%i]\n",s);
  SendSock(irc->socket,"NICK PenisEnvy\nUSER PenisEnvy 0 0 UbieDubie\n");
  SendSock(irc->socket,"JOIN #UbixOS\n");
  while (1) {
    if (ReadSock(irc->socket,output)) {
      printf("%s\n",output);
      IRCParse(output,irc);
      if (!strcasecmp(irc->command,"PRIVMSG")) {
        IRCPrivmsg(irc);
        }
      }
    }
  return(0);
  }

char *GetField(char *newline,int ch) {
  static  char *line = NULL;
  char    *end, *field;
 
  if (newline)
    line = newline;
  if (line == NULL)
    return(NULL);
  field = line;
  if ((end = (char *)index(line,ch)) == NULL) {
    line = NULL;
    if ((end = (char *)index(field,'\n')) == NULL)
      end = field + strlen(field);
    }
  else
    line = end + 1; *end = '\0';
 
  return(field);
  }