Ok i created this irc bot( finaly got it working ) but i have one problem... when i want to get a certain input let's say.. hey
then i want it to say you, but for some reason i have to send this PRIVMSG #coding hey
to get this PRIVMSG #h4ckerx :you
but i just want to get the word hey etc and make my bot say you with out me writing PRIVMSG #coding hey in the chan.. another thing is.. that if i was to kick my bot, the connection is still running.. like if i was to try to join again with the same bot name i will get an error( nick all ready in use ) any help?
Code:
mysock.sin_family = AF_INET;
mysock.sin_port = htons( port );
mysock.sin_addr = *((struct in_addr *)host->h_addr);
memset(&(mysock.sin_zero), '\0', 8);
system( "clear" );
printf( "-- Looking up %s...\n", argv[1] );
printf( "-- Connecting to %s (%s) port %s\n",host->h_name, inet_ntoa(*(struct in_addr *)host->h_addr ), argv[2] );
printf( "-- Connected. Now logging in..\n" );
if(cc = connect( sp, ( struct sockaddr *)&mysock, sizeof mysock) == -1 )
{
perror( "connect" );
exit( 1 );
}
sleep(1);
sendargv(sp,"NICK Gost\n\r");
sendargv(sp,"USER localhost localhost localhost : gost\n\r");
sendargv(sp,"JOIN #code\n\r");
sendargv(sp,"USER localhost:gost\n\r");
for( ;; )
{
recv(sp, buff, sizeof(buff), 0 );
if(buff[strlen(buff)-1] == '\n')
buff[strlen(buff)-1] = '\0';
if (strstr(buff, "474"))
// if bot is banned do this.
if(strstr(buff, "433"))
sendargv(sp,"NICK BOT\r\n" );
if(strstr(buff, "PRIVMSG:"))
if(strstr( buff, "PRIVMSG #code hey" ))
sendargv( sp, "PRIVMSG #code :you\r\n" );
if(strstr(buff, "PING :"))
{
fprintf(stdout,"[$] PING! sending PONG.\n");
ping = strtok(buff,"PING:");
sendargv(sp,"PONG :%s\n\r", ping);
}
fprintf(stdout, "-- %s\n", buff);
memset(buff, 0, sizeof(buff));
}
close( sp );
return 0;
}
int sendargv( int s, char *text, ... )
{
static char buff[1024];
va_list ap;
va_start(ap, text);
vsprintf(buff, text, ap);
va_end( ap );
return write(s,buff, strlen(buff));
}