83 lines
3.0 KiB
C++
83 lines
3.0 KiB
C++
#include "botapp.h"
|
|
#include "mainwindow.h"
|
|
#include "ircbot.h"
|
|
#include "socketirc.h"
|
|
#include "console.h"
|
|
|
|
BotApp::BotApp(int argc, char** argv) : nogui(false)
|
|
{
|
|
QString server = QString("irc.freenode.net");
|
|
int port = 6667;
|
|
QString nick = QString("SparrowBotDebug");
|
|
QString chan = QString("epicsparrow");
|
|
QString pass;
|
|
|
|
// parsing arguments
|
|
for(int i=1; i<argc; ++i)
|
|
{
|
|
QString str = QString(argv[i]);
|
|
if(str.compare("-nogui") == 0)
|
|
nogui = true;
|
|
else if(str.contains('='))
|
|
{
|
|
QStringList argList = str.split('=');
|
|
if(argList.size() == 2)
|
|
{
|
|
QString key = argList.at(0);
|
|
if(key.compare("server") == 0)
|
|
server = argList.at(1);
|
|
else if(key.compare("port") == 0)
|
|
port = argList.at(1).toInt();
|
|
else if(key.compare("nick") == 0)
|
|
nick = argList.at(1);
|
|
else if(key.compare("chan") == 0)
|
|
chan = argList.at(1);
|
|
else if(key.compare("pass") == 0)
|
|
pass = argList.at(1);
|
|
}
|
|
}
|
|
}
|
|
|
|
sock = new SocketIRC(server, port);
|
|
bot = new IRCBot(nick, chan, pass);
|
|
if(nogui)
|
|
coreApp = new QCoreApplication(argc, argv);
|
|
else
|
|
coreApp = new QApplication(argc, argv);
|
|
|
|
QObject::connect(sock, SIGNAL(receivedMsg(QString)), bot, SLOT(receiveMsg(QString)));
|
|
QObject::connect(bot, SIGNAL(sendMsg(QString)), sock, SLOT(sendMsg(QString)));
|
|
QObject::connect(coreApp, SIGNAL(aboutToQuit()), bot, SLOT(disconnect()));
|
|
}
|
|
|
|
BotApp::~BotApp()
|
|
{
|
|
delete(sock);
|
|
delete(bot);
|
|
if(!nogui)
|
|
delete(window);
|
|
}
|
|
|
|
int BotApp::exec()
|
|
{
|
|
if(!nogui)
|
|
{
|
|
window = new MainWindow(bot->getChan());
|
|
QObject::connect(sock, SIGNAL(receivedMsg(QString)), window->getAdvancedConsole(), SLOT(appendAdvancedMsg(QString)));
|
|
QObject::connect(bot, SIGNAL(sendMsg(QString)), window->getAdvancedConsole(), SLOT(appendAdvancedMsg(QString)));
|
|
QObject::connect(sock, SIGNAL(receivedMsg(QString)), window->getSimpleConsole(), SLOT(appendSimpleMsg(QString)));
|
|
QObject::connect(bot, SIGNAL(sendMsg(QString)), window->getSimpleConsole(), SLOT(appendSimpleMsg(QString)));
|
|
QObject::connect((QObject*)window->getAdvancedPrompt(), SIGNAL(sendMsg(QString)), sock, SLOT(sendMsg(QString)));
|
|
QObject::connect((QObject*)window->getAdvancedPrompt(), SIGNAL(returnPressed()), (QObject*)window->getAdvancedPrompt(), SLOT(advancedConfirmationPerformed()));
|
|
QObject::connect((QObject*)window->getSimplePrompt(), SIGNAL(sendMsg(QString)), sock, SLOT(sendMsg(QString)));
|
|
QObject::connect((QObject*)window->getSimplePrompt(), SIGNAL(returnPressed()), (QObject*)window->getSimplePrompt(), SLOT(simpleConfirmationPerformed()));
|
|
window->show();
|
|
}
|
|
return sock->connectToServer(coreApp);
|
|
}
|
|
|
|
void BotApp::addModule(Module* module)
|
|
{
|
|
bot->addModule(module);
|
|
}
|