75 lines
2.2 KiB
C++
75 lines
2.2 KiB
C++
#include "botapp.h"
|
|
#include "mainwindow.h"
|
|
#include "ircbot.h"
|
|
#include "socketirc.h"
|
|
|
|
BotApp::BotApp(int argc, char** argv) :
|
|
nogui(false),
|
|
server("irc.freenode.net"),
|
|
port(6667),
|
|
nick("SparrowBotDebug"),
|
|
chan("epicsparrow")
|
|
{
|
|
// 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);
|
|
}
|
|
}
|
|
}
|
|
|
|
sock = new SocketIRC(server, port);
|
|
bot = new IRCBot(nick, chan);
|
|
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();
|
|
QObject::connect(sock, SIGNAL(receivedMsg(QString)), (QObject*)window->getConsole(), SLOT(append(QString)));
|
|
QObject::connect(bot, SIGNAL(sendMsg(QString)), (QObject*)window->getConsole(), SLOT(append(QString)));
|
|
QObject::connect((QObject*)window->getPrompt(), SIGNAL(sendMsg(QString)), sock, SLOT(sendMsg(QString)));
|
|
QObject::connect((QObject*)window->getPrompt(), SIGNAL(returnPressed()), (QObject*)window->getPrompt(), SLOT(confirmationPerformed()));
|
|
window->show();
|
|
}
|
|
return sock->connectToServer(coreApp);
|
|
}
|
|
|
|
void BotApp::addModule(Module* module)
|
|
{
|
|
bot->addModule(module);
|
|
}
|