/*
bot.c (C) 2007 Christopher Olsen
$Id$
*/
#include <stdio.h>
#include "tuvebot.h"
int botJoinChans() {
MYSQL_RES *res = 0x0;
MYSQL_ROW row;
unsigned int i = 0x0;
res = dbQuery("SELECT channel,topic,modes FROM channels",1);
for (i = 0;i < mysql_num_rows(res);i++) {
row = mysql_fetch_row(res);
sWriteSocket("JOIN %s\n",row[0]);
if (row[1] != 0x0) {
//sleep(1);
sWriteSocket("TOPIC %s:%s\n",row[0],row[1]);
}
if (row[2] != 0x0) {
//sleep(1);
sWriteSocket("MSG %s:.tv mode %s\n",row[0],row[2]);
}
}
return(0x0);
}
int botSetCurSong(char *data) {
char output[128];
char *chan = 0x0;
char *song = 0x0;
writeLog(0,"TESTING");
if (data == 0x0)
return(-1);
chan = strtok(data,":");
strtok(NULL,":");
strtok(NULL,":");
strtok(NULL,":");
strtok(NULL,":");
song = strtok(NULL,":");
if (song == 0x0)
return(-1);
sprintf(output,"UPDATE channels SET nowplaying = %s WHERE channel = '%s'",song,chan);
dbQuery(output,0);
writeLog(0,"Test: %s %s\n",chan,song);
return(0x0);
}
int botStoreTopic(char *data) {
char *chan = 0x0;
char *topic = 0x0;
char qStr[512];
if (data == 0x0)
return(0x1);
chan = strtok(data,":");
topic = strtok(NULL,"\n");
if (chan == 0x0)
return(0x1);
sprintf(qStr,"UPDATE channels SET topic = \"%s\" WHERE channel = '%s'",topic,chan);
dbQuery(qStr,0);
return(0x0);
}