Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ctime>
- #include <iostream>
- #include <my_global.h>
- #include <mysql.h>
- #include "bot.h"
- #include "sicl.h"
- #include "srfl.h"
- #include "stristr.cpp"
- using namespace SPS;
- using namespace std;
- int main()
- {
- SICL *irc = new SICL();
- SRFL *misc = new SRFL();
- cout << "WAT " << VERSION_STR << " -- Using MySQL " << mysql_get_client_info() << ", SICL " << irc->GetVersion() << ", and SRFL " << misc->GetVersion() << "\n";
- cout << "Created by Snai\n\n";
- FILE *ini = fopen("bot.ini", "r");
- if(ini)
- {
- bool direct = false;
- bool directed = false;
- bool first = true;
- bool first2 = true;
- bool flood = false;
- bool waitForAnswer = false;
- bool waitForNick = false;
- char *buf353 = new char[1024];
- char *channel = new char[1024];
- char *contents = new char[1024 * 64];
- char *direct2 = new char[1024];
- char *email = new char[1024];
- char *lastChannel = new char[1024];
- char *lastNick = new char[1024];
- char *lastQuestion = new char[1024 * 64];
- char *lastQuestion2 = new char[1024 * 64];
- char *master = new char[1024];
- char *mysqlDatabase = new char[1024];
- char *mysqlPassword = new char[1024];
- char *mysqlPort = new char[1024];
- char *mysqlServer = new char[1024];
- char *mysqlUser = new char[1024];
- char *nick = new char[1024];
- char *password = new char[1024];
- char *port = new char[1024];
- char *server = new char[1024];
- char *user = new char[1024];
- char *users[1024];
- char *happy[5];
- char *responses[5];
- for(int i = 0; i < 5; i++)
- {
- happy[i] = new char[1024];
- responses[i] = new char[1024];
- memset(happy[i], 0, 1024);
- memset(responses[i], 0, 1024);
- }
- _snprintf(responses[0], 1023, "You fucking spammer.");
- _snprintf(responses[1], 1023, "Why so spam");
- _snprintf(responses[2], 1023, "SPAMMAR");
- _snprintf(responses[3], 1023, "%cACTION goes brb for 60 secs.%c", 1, 1);
- _snprintf(responses[4], 1023, "YOU ARE A DAMN SPAMMER");
- _snprintf(happy[0], 1023, "kdone");
- _snprintf(happy[1], 1023, "i r back");
- _snprintf(happy[2], 1023, "I decided to get some lube. But I am back now.");
- _snprintf(happy[3], 1023, "Back. Please do not feather me.");
- _snprintf(happy[4], 1023, "%cACTION walks back into the room without realizing he forgot his dildo%c", 1, 1);
- float currentTickCount = 0.0f;
- float lastTickCount = 0.0f;
- int count = 0;
- for(int i = 0; i < 1023; i++)
- {
- users[i] = new char[1024];
- memset(users[i], 0, 1024);
- }
- int position = 0;
- memset(buf353, 0, 1024);
- memset(channel, 0, 1024);
- memset(contents, 0, 1024 * 64);
- memset(direct2, 0, 1024);
- memset(email, 0, 1024);
- memset(lastChannel, 0, 1024);
- memset(lastNick, 0, 1024);
- memset(lastQuestion, 0, 1024);
- memset(master, 0, 1024);
- memset(mysqlDatabase, 0, 1024);
- memset(mysqlPassword, 0, 1024);
- memset(mysqlPort, 0, 1024);
- memset(mysqlServer, 0, 1024);
- memset(mysqlUser, 0, 1024);
- memset(nick, 0, 1024);
- memset(password, 0, 1024);
- memset(port, 0, 1024);
- memset(server, 0, 1024);
- memset(user, 0, 1024);
- fread(contents, 1, (1024 * 64) - 1, ini);
- fclose(ini);
- char *silentTest = new char[1024];
- memset(silentTest, 0, 1024);
- misc->CopyIniValue(contents, "[irc]", "direct = ", direct2);
- misc->CopyIniValue(contents, "[irc]", "silent = ", silentTest);
- bool silent = false;
- if(!_stricmp(silentTest, "false"))
- silent = false;
- else if(!_stricmp(silentTest, "true"))
- silent = true;
- else
- silent = false;
- if(!_stricmp(direct2, "false"))
- direct = false;
- else if(!_stricmp(direct2, "true"))
- direct = true;
- else
- direct = false;
- delete direct2;
- delete silentTest;
- misc->CopyIniValue(contents, "[irc]", "channel = ", channel);
- misc->CopyIniValue(contents, "[irc]", "email = ", email);
- misc->CopyIniValue(contents, "[irc]", "master = ", master);
- misc->CopyIniValue(contents, "[irc]", "nick = ", nick);
- misc->CopyIniValue(contents, "[irc]", "password = ", password);
- misc->CopyIniValue(contents, "[irc]", "port = ", port);
- misc->CopyIniValue(contents, "[irc]", "server = ", server);
- misc->CopyIniValue(contents, "[irc]", "user = ", user);
- misc->CopyIniValue(contents, "[mysql]", "database = ", mysqlDatabase);
- misc->CopyIniValue(contents, "[mysql]", "password = ", mysqlPassword);
- misc->CopyIniValue(contents, "[mysql]", "port = ", mysqlPort);
- misc->CopyIniValue(contents, "[mysql]", "server = ", mysqlServer);
- misc->CopyIniValue(contents, "[mysql]", "user = ", mysqlUser);
- _snprintf(buf353, 1023, " 353 %s", nick);
- irc->Connect(server, atoi(port));
- irc->Send("USER %s %s %s :%s\r\n", user, user, user, user);
- irc->Send("NICK %s\r\n", nick);
- char *received = new char[1024 * 64];
- memset(received, 0, (1024 * 64) - 1);
- MYSQL *mysql = mysql_init(0);
- if(mysql)
- {
- if(mysql_real_connect(mysql, mysqlServer, mysqlUser, mysqlPassword, mysqlDatabase, atoi(mysqlPort), 0, 0))
- {
- bool answer = false;
- cout << "Connected to " << mysqlServer << ":" << mysqlPort << "\n";
- while(irc->Receive(received, (1024 * 64) - 1) > 0)
- {
- currentTickCount = clock() * 0.001f;
- for(int i = 0; i < (int)strlen(received); i++)
- {
- if(received[i] == '%')
- received[i] = '^';
- }
- if(strstr(received, "PING :"))
- {
- if(first)
- {
- irc->Send("PRIVMSG NickServ :REGISTER %s %s\r\n", password, email);
- irc->Send("PRIVMSG NickServ :REGISTER %s %s %s %s\r\n", password, password, email, email);
- irc->Send("PRIVMSG NickServ :IDENTIFY %s\r\n", password);
- first = false;
- }
- char *pong = new char[1024];
- memset(pong, 0, 1024);
- misc->CopySubString(received, "PING :", "\r", pong);
- irc->Send("PONG :%s\r\n", pong);
- delete pong;
- }
- if(stristr(received, "End") && first2)
- {
- first2 = false;
- irc->Send("PRIVMSG NickServ :IDENTIFY %s\r\n", password);
- irc->Send("JOIN %s\r\n", channel);
- irc->Send("NAMES %s\r\n", channel);
- cout << "Connected to " << server << ":" << port << "\n";
- }
- if(stristr(received, " KICK #") && !stristr(received, "PRIVMSG"))
- {
- char *nickname2 = new char[1024];
- char *channel2 = new char[1024];
- memset(nickname2, 0, 1024);
- memset(channel2, 0, 1024);
- misc->CopySubString(received, " KICK #", " ", channel2);
- misc->CopySubString(stristr(received, " KICK #"), channel2, " :", nickname2);
- char *nickname3 = (nickname2 + 1);
- if(!_stricmp(nick, nickname3))
- irc->Send("JOIN #%s\r\n", channel2);
- delete nickname2;
- delete channel2;
- }
- if(stristr(received, "Cannot join channel") && !stristr(received, "PRIVMSG"))
- {
- char *channel2 = new char[1024];
- memset(channel2, 0, 1024);
- misc->CopySubString(received, nick, " :Cannot join channel", channel2);
- char *channel3 = (channel2 + 2);
- irc->Send("JOIN #%s\r\n", channel3);
- delete channel2;
- }
- if(strstr(received, " JOIN :#") && !stristr(received, "PRIVMSG"))
- {
- char *nickname = new char[1024];
- memset(nickname, 0, 1024);
- misc->CopySubString(received, ":", "!", nickname);
- bool nickFound = false;
- char *nickname2 = nickname;
- if(stristr(nickname2, ":") == nickname2)
- nickname2++;
- for(int i = 0; i < position; i++)
- {
- if(!strcmp(users[i], nickname2))
- nickFound = true;
- }
- if(!nickFound)
- {
- if(position >= 1022)
- {
- position = 0;
- for(int i = 0; i < 1023; i++)
- memset(users[i], 0, 1024);
- irc->Send("NAMES %s\r\n", channel);
- }
- else
- {
- _snprintf(users[position], 1023, nickname2);
- cout << "Nick found: " << users[position] << "\n";
- position++;
- }
- }
- delete nickname;
- }
- if(strstr(received, " NICK ") && !stristr(received, "PRIVMSG"))
- {
- char *nickname = new char[1024];
- memset(nickname, 0, 1024);
- misc->CopySubString(received, " NICK ", "\r", nickname);
- bool nickFound = false;
- char *nickname2 = nickname;
- if(stristr(nickname2, ":") == nickname2)
- nickname2++;
- for(int i = 0; i < position; i++)
- {
- if(!strcmp(users[i], nickname2))
- nickFound = true;
- }
- if(!nickFound)
- {
- if(position >= 1024)
- {
- position = 0;
- for(int i = 0; i < 1023; i++)
- memset(users[i], 0, 1024);
- irc->Send("NAMES %s\r\n", channel);
- }
- else
- {
- _snprintf(users[position], 1023, nickname2);
- cout << "Nick found: " << users[position] << "\n";
- position++;
- }
- }
- delete nickname;
- }
- if(strstr(received, buf353) && !stristr(received, "PRIVMSG #"))
- {
- char *buf = new char[1024 * 64];
- memset(buf, 0, (1024 * 64) - 1);
- misc->CopySubString(received, buf353, "\r", buf);
- char *place = (strstr(buf, " :") + 2);
- place = strtok(place, " ");
- bool nickFound = false;
- char *place2;
- while(place)
- {
- if((place[0] == '+') || (place[0] == '@') || (place[0] == '^') || (place[0] == '~') || (place[0] == '&'))
- {
- if((place[1] == '+') || (place[1] == '@') || (place[1] == '^') || (place[1] == '~') || (place[1] == '&'))
- place2 = (place + 2);
- else
- place2 = (place + 1);
- }
- else
- place2 = place;
- char *nickname2 = place2;
- if(stristr(nickname2, ":") == nickname2)
- nickname2++;
- for(int i = 0; i < position; i++)
- {
- if(!strcmp(users[i], nickname2))
- nickFound = true;
- }
- if(!nickFound)
- {
- if(position >= 1024)
- {
- position = 0;
- for(int i = 0; i < 1023; i++)
- memset(users[i], 0, 1024);
- irc->Send("NAMES %s\r\n", channel);
- }
- else
- {
- _snprintf(users[position], 1023, nickname2);
- cout << "Nick found: " << users[position] << "\n";
- position++;
- }
- }
- nickFound = false;
- place = strtok(0, " ");
- }
- delete buf;
- }
- if(strstr(received, " PRIVMSG #"))
- {
- char *currentChannel = new char[1024];
- char *host = new char[1024];
- char *mastername = new char[1024];
- char *nickname = new char[1024];
- char *question = new char[1024 * 64];
- char *username = new char[1024];
- memset(currentChannel, 0, 1024);
- memset(host, 0, 1024);
- memset(mastername, 0, 1024);
- memset(nickname, 0, 1024);
- memset(question, 0, 1024 * 64);
- memset(username, 0, 1024);
- misc->CopySubString(received, "#", " :", currentChannel);
- misc->CopySubString(received, ":", " ", mastername);
- misc->CopySubString(received, ":", "!", nickname);
- misc->CopySubString(received, "!", "@", username);
- misc->CopySubString(received, "@", " ", host);
- misc->CopySubString(received, " :", "\r", question);
- for(int i = 0; i < (int)strlen(question); i++)
- {
- if(question[i] == '\'')
- question[i] = '`';
- else if(question[i] == '\\')
- question[i] = '/';
- }
- if(!strcmp(mastername, master))
- {
- if(stristr(question, "!join #") == question)
- {
- char *join = (stristr(question, "!join #") + strlen("!join #"));
- irc->Send("JOIN #%s\r\n", join);
- }
- else if(stristr(question, "!part #") == question)
- {
- char *part = (stristr(question, "!part #") + strlen("!part #"));
- irc->Send("PART #%s\r\n", part);
- }
- else if(stristr(question, "!master ") == question)
- {
- char *mastername2 = (stristr(question, "!master ") + strlen("!master "));
- memset(master, 0, 1023);
- _snprintf(master, 1023, mastername2);
- irc->Send("PRIVMSG #%s :'%s' is now my master.\r\n", currentChannel, master);
- }
- else if(!_stricmp(question, "!silent = false"))
- silent = false;
- else if(!_stricmp(question, "!silent = true"))
- silent = true;
- else if(!_stricmp(question, "!direct = false"))
- direct = false;
- else if(!_stricmp(question, "!direct = true"))
- direct = true;
- else if(!_stricmp(question, "!quit"))
- irc->Send("QUIT :WAT %s -- Using MySQL %s, SICL %s, and SRFL %s -- Created by Snail\r\n", VERSION_STR, mysql_get_client_info(), irc->GetVersion(), misc->GetVersion());
- else if(!_stricmp(question, "!stats"))
- {
- mysql_query(mysql, "SELECT * FROM data");
- MYSQL_RES *result = mysql_store_result(mysql);
- MYSQL_ROW row;
- int questions = 0;
- unsigned long bytes = 0;
- while((row = mysql_fetch_row(result)))
- {
- for(int i = 0; i < (int)mysql_num_fields(result); i++)
- bytes += strlen(row[i]);
- questions++;
- }
- mysql_free_result(result);
- mysql_query(mysql, "SELECT * FROM users");
- result = mysql_store_result(mysql);
- int users = 0;
- while((row = mysql_fetch_row(result)))
- {
- for(int i = 0; i < (int)mysql_num_fields(result); i++)
- bytes += strlen(row[i]);
- users++;
- }
- mysql_free_result(result);
- char *buft = new char[1024 * 64];
- memset(buft, 0, 1024 * 64);
- _snprintf(buft, (1024 * 64) - 1, "PRIVMSG #%s :My database contains %u unique entries from %u different users. Also, I think the size of my database is about %.02f MB.\r\n", currentChannel, questions, users, (bytes / 1024.0f) / 1024.0f);
- irc->Send(buft);
- delete buft;
- }
- else if(stristr(question, "!rewrite |q|") == question)
- {
- if(stristr(question, "|a|"))
- {
- char *answer = (stristr(question, "|a|") + 3);
- char *question2 = new char[1024 * 64];
- memset(question2, 0, 1024 * 64);
- misc->CopySubStringI(question, "|q|", "|a|", question2);
- char *bufz = new char[1024 * 64];
- memset(bufz, 0, 1024 * 64);
- _snprintf(bufz, (1024 * 64) - 1, "UPDATE data set answer = '%s' WHERE question = '%s';", answer, question2);
- mysql_query(mysql, bufz);
- delete bufz;
- delete question2;
- }
- }
- else if(stristr(question, "!lookup "))
- {
- mysql_query(mysql, "SELECT * FROM users");
- MYSQL_RES *result = mysql_store_result(mysql);
- MYSQL_ROW row;
- char *nicktmp = (stristr(question, "!lookup ") + strlen("!lookup "));
- irc->Send("PRIVMSG %s :Here is a list of records containing the nick '%s':\r\n", nickname, nicktmp);
- bool found = false;
- while((row = mysql_fetch_row(result)))
- {
- if(stristr(row[1], nicktmp))
- {
- irc->Send("PRIVMSG %s :- %s!%s@%s\r\n", nickname, row[1], row[2], row[3]);
- found = true;
- Sleep(500);
- }
- }
- mysql_free_result(result);
- if(!found)
- irc->Send("PRIVMSG %s :Sorry, no records of '%s' exist in my database.\r\n", nickname, nicktmp);
- }
- else if(stristr(question, "!lookuphost "))
- {
- mysql_query(mysql, "SELECT * FROM users");
- MYSQL_RES *result = mysql_store_result(mysql);
- MYSQL_ROW row;
- char *nicktmp = (stristr(question, "!lookuphost ") + strlen("!lookuphost "));
- irc->Send("PRIVMSG %s :Here is a list of records containing the host '%s':\r\n", nickname, nicktmp);
- bool found = false;
- while((row = mysql_fetch_row(result)))
- {
- if(stristr(row[3], nicktmp))
- {
- irc->Send("PRIVMSG %s :- %s!%s@%s\r\n", nickname, row[1], row[2], row[3]);
- found = true;
- Sleep(500);
- }
- }
- mysql_free_result(result);
- if(!found)
- irc->Send("PRIVMSG %s :Sorry, no records of '%s' exist in my database.\r\n", nickname, nicktmp);
- }
- else if(stristr(question, "!lookupuser "))
- {
- mysql_query(mysql, "SELECT * FROM users");
- MYSQL_RES *result = mysql_store_result(mysql);
- MYSQL_ROW row;
- char *nicktmp = (stristr(question, "!lookupuser ") + strlen("!lookupuser "));
- irc->Send("PRIVMSG %s :Here is a list of records containing the user '%s':\r\n", nickname, nicktmp);
- bool found = false;
- while((row = mysql_fetch_row(result)))
- {
- if(stristr(row[2], nicktmp))
- {
- irc->Send("PRIVMSG %s :- %s!%s@%s\r\n", nickname, row[1], row[2], row[3]);
- found = true;
- Sleep(500);
- }
- }
- mysql_free_result(result);
- if(!found)
- irc->Send("PRIVMSG %s :Sorry, no records of '%s' exist in my database.\r\n", nickname, nicktmp);
- }
- else if(stristr(question, "!quit ") == question)
- {
- char *quit = (stristr(question, "!quit ") + strlen("!quit "));
- irc->Send("QUIT :%s\r\n", quit);
- }
- }
- if(answer && waitForNick && (strstr(question, "!") != question) && (strcmp(lastNick, nickname) != 0) && !strcmp(lastChannel, currentChannel))
- {
- waitForAnswer = false;
- mysql_query(mysql, "SELECT * FROM users");
- MYSQL_RES *result = mysql_store_result(mysql);
- MYSQL_ROW row;
- bool found = false;
- while((row = mysql_fetch_row(result)))
- {
- if((!strcmp(row[1], nickname)) && (!strcmp(row[2], username)) && (!strcmp(row[3], host)))
- {
- found = true;
- break;
- }
- }
- if(!found)
- {
- char *buf = new char[1024 * 64];
- memset(buf, 0, 1024 * 64);
- _snprintf(buf, (1024 * 64) - 1, "INSERT INTO users (nick, user, host) VALUES ('%s', '%s', '%s');", nickname, username, host);
- mysql_query(mysql, buf);
- cout << "New user: " << nickname << "!" << username << "@" << host << "\n";
- delete buf;
- }
- mysql_free_result(result);
- char *buf = new char[1024 * 64];
- memset(buf, 0, 1024 * 64);
- char *questionx = question;
- for(int i = 0; i < position; i++)
- {
- if((stristr(questionx, users[i]) == questionx) && ((strstr(questionx, ":") == (questionx + strlen(users[i]))) || (strstr(questionx, ",") == (questionx + strlen(users[i])))))
- questionx += (strlen(users[i]) + 2);
- else if((stristr(questionx, users[i]) == questionx) && (strstr(questionx, " ") == (questionx + strlen(users[i]))))
- questionx += (strlen(users[i]) + 1);
- else if((questionx[0] == '@') && (stristr(questionx, users[i]) == (questionx + 1)) && (stristr(questionx, " ") == (questionx + (strlen(users[i]) + 1))))
- questionx += (strlen(users[i]) + 2);
- else if((questionx[0] == '@') && (stristr(questionx, users[i]) == (questionx + 1)) && (stristr(questionx, " ") == (questionx + (strlen(users[i]) + 2))) && ((stristr(questionx, ",") == (questionx + (strlen(users[i]) + 1)))) || (stristr(questionx, ":") == (questionx + (strlen(users[i]) + 1))))
- questionx += (strlen(users[i]) + 3);
- }
- _snprintf(buf, (1024 * 64) - 1, "UPDATE data set answer = '%s' WHERE question = '%s';", questionx, lastQuestion);
- cout << "Found new entry: " << lastQuestion << " -> " << questionx << "\n";
- mysql_query(mysql, buf);
- if(directed && !silent)
- directed = false;
- }
- if((strstr(question, "!") != question))
- {
- mysql_query(mysql, "SELECT * FROM users");
- MYSQL_RES *result = mysql_store_result(mysql);
- MYSQL_ROW row;
- bool found = false;
- while((row = mysql_fetch_row(result)))
- {
- if((!strcmp(row[1], nickname)) && (!strcmp(row[2], username)) && (!strcmp(row[3], host)))
- {
- found = true;
- break;
- }
- }
- if(!found)
- {
- char *buf = new char[1024 * 64];
- memset(buf, 0, 1024 * 64);
- _snprintf(buf, (1024 * 64) - 1, "INSERT INTO users (nick, user, host) VALUES ('%s', '%s', '%s');", nickname, username, host);
- mysql_query(mysql, buf);
- cout << "New user: " << nickname << "!" << username << "@" << host << "\n";
- delete buf;
- }
- found = false;
- mysql_free_result(result);
- mysql_query(mysql, "SELECT * FROM data");
- result = mysql_store_result(mysql);
- char *questionx = question;
- for(int i = 0; i < position; i++)
- {
- if((stristr(questionx, users[i]) == questionx) && ((strstr(questionx, ":") == (questionx + strlen(users[i]))) || (strstr(questionx, ",") == (questionx + strlen(users[i])))))
- questionx += (strlen(users[i]) + 2);
- else if((stristr(questionx, users[i]) == questionx) && (strstr(questionx, " ") == (questionx + strlen(users[i]))))
- questionx += (strlen(users[i]) + 1);
- else if((questionx[0] == '@') && (stristr(questionx, users[i]) == (questionx + 1)) && (stristr(questionx, " ") == (questionx + (strlen(users[i]) + 1))))
- questionx += (strlen(users[i]) + 2);
- else if((questionx[0] == '@') && (stristr(questionx, users[i]) == (questionx + 1)) && (stristr(questionx, " ") == (questionx + (strlen(users[i]) + 2))) && ((stristr(questionx, ",") == (questionx + (strlen(users[i]) + 1)))) || (stristr(questionx, ":") == (questionx + (strlen(users[i]) + 1))))
- questionx += (strlen(users[i]) + 3);
- }
- while((row = mysql_fetch_row(result)))
- {
- if(!_stricmp(row[1], questionx))
- {
- found = true;
- break;
- }
- }
- if(flood)
- {
- if((currentTickCount - lastTickCount) >= 60.0f)
- {
- flood = false;
- count = 0;
- memset(lastQuestion2, 0, 1024 * 64);
- if(!silent)
- {
- srand((unsigned int)time(0));
- irc->Send("PRIVMSG #%s :%s\r\n", currentChannel, happy[rand() % 5]);
- }
- }
- }
- if(found && !silent && !flood)
- {
- bool go = false;
- if((stristr(question, nick) == question) && (question[0] != '@') && direct)
- {
- if(_stricmp(lastQuestion2, row[2]) != 0)
- go = true;
- }
- else if((stristr(question, nick) == (question + 1)) && (question[0] == '@') && direct)
- {
- if(_stricmp(lastQuestion2, row[2]) != 0)
- go = true;
- }
- else if((stristr(question, nick) == (question + 1)) && (question[0] == '@') && !direct)
- {
- if(_stricmp(lastQuestion2, row[2]) != 0)
- go = true;
- }
- else if((stristr(question, nick) == question) && (question[0] != '@') && !direct)
- {
- if(_stricmp(lastQuestion2, row[2]) != 0)
- go = true;
- }
- else if((stristr(question, nick) != question) && !direct)
- {
- if(_stricmp(lastQuestion2, row[2]) != 0)
- go = true;
- }
- if(go)
- {
- count = 0;
- memset(lastQuestion2, 0, 1024 * 64);
- _snprintf(lastQuestion2, (1024 * 64) - 1, row[2]);
- }
- if((count < 2) && ((direct && stristr(question, nick)) || !direct))
- irc->Send("PRIVMSG #%s :%s\r\n", currentChannel, row[2]);
- if(!_stricmp(lastQuestion2, row[2]))
- {
- count++;
- memset(lastQuestion2, 0, 1024 * 64);
- _snprintf(lastQuestion2, (1024 * 64) - 1, row[2]);
- if(count >= 3)
- {
- flood = true;
- lastTickCount = currentTickCount;
- srand((unsigned int)time(0));
- irc->Send("PRIVMSG #%s :%s, %s\r\n", currentChannel, nickname, responses[rand() % 5]);
- }
- }
- }
- else if(!waitForAnswer && !found && !answer && !waitForNick)
- {
- waitForAnswer = true;
- waitForNick = true;
- char *buf = new char[1024 * 64];
- memset(buf, 0, 1024 * 64);
- _snprintf(buf, (1024 * 64) - 1, "INSERT INTO data (question) VALUES ('%s');", questionx);
- memset(lastQuestion, 0, 1024 * 64);
- _snprintf(lastQuestion, (1024 * 64) - 1, questionx);
- mysql_query(mysql, buf);
- delete buf;
- answer = true;
- memset(lastNick, 0, 1024);
- _snprintf(lastNick, 1023, nickname);
- memset(lastChannel, 0, 1024);
- _snprintf(lastChannel, 1023, currentChannel);
- if(stristr(question, nick) && !silent)
- directed = true;
- }
- mysql_free_result(result);
- }
- delete currentChannel;
- delete host;
- delete nickname;
- delete question;
- delete username;
- if(!waitForAnswer)
- {
- answer = false;
- waitForNick = false;
- }
- }
- memset(received, 0, (1024 * 64) - 1);
- }
- mysql_close(mysql);
- }
- else
- cout << "Error #" << mysql_errno(mysql) << ": " << mysql_error(mysql) << "\n";
- }
- else
- cout << "Error #" << mysql_errno(mysql) << ": " << mysql_error(mysql) << "\n";
- delete buf353;
- delete channel;
- delete contents;
- delete email;
- delete lastChannel;
- delete lastNick;
- delete lastQuestion;
- delete lastQuestion2;
- delete master;
- delete mysqlDatabase;
- delete mysqlPassword;
- delete mysqlPort;
- delete mysqlServer;
- delete mysqlUser;
- delete nick;
- delete password;
- delete port;
- delete received;
- delete server;
- delete user;
- for(int i = 0; i < 1023; i++)
- delete users[i];
- for(int i = 0; i < 5; i++)
- {
- delete happy[i];
- delete responses[i];
- }
- }
- else
- cout << "Error: could not load 'bot.ini'\n";
- irc->~SICL();
- misc->~SRFL();
- delete irc;
- delete misc;
- Sleep(10000);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement