75 lines
2.2 KiB
C++
75 lines
2.2 KiB
C++
#include "mainwindow.h"
|
|
#include "socketirc.h"
|
|
#include "sparrowbot.h"
|
|
#include <QApplication>
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
bool nogui = false;
|
|
QString server = "irc.freenode.net";
|
|
int port = 6667;
|
|
QString nick = "SparrowBotDebug";
|
|
QString 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('=');
|
|
QString key = argList.at(0);
|
|
if(key.compare("server"))
|
|
server = argList.at(1);
|
|
else if(key.compare("port"))
|
|
port = argList.at(1).toInt();
|
|
else if(key.compare("nick"))
|
|
nick = argList.at(1);
|
|
else if(key.compare("chan"))
|
|
chan = argList.at(1);
|
|
}
|
|
}
|
|
|
|
// create the socket
|
|
SocketIRC sock;
|
|
sock.setServer(server);
|
|
sock.setPort(port);
|
|
|
|
// create the bot
|
|
SparrowBot* bot = new SparrowBot(nick, chan);
|
|
|
|
// connect the bot to the socket
|
|
QObject::connect(&sock, SIGNAL(receivedMsg(QString)), bot, SLOT(receiveMsg(QString)));
|
|
QObject::connect(bot, SIGNAL(sendMsg(QString)), &sock, SLOT(sendMsg(QString)));
|
|
|
|
// set up UI
|
|
if(!nogui)
|
|
{
|
|
QApplication app(argc, argv);
|
|
|
|
// init window
|
|
MainWindow w;
|
|
QObject::connect(&sock, SIGNAL(receivedMsg(QString)), w.getConsole(), SLOT(append(QString)));
|
|
QObject::connect(bot, SIGNAL(sendMsg(QString)), w.getConsole(), SLOT(append(QString)));
|
|
QObject::connect(w.getPrompt(), SIGNAL(sendMsg(QString)), &sock, SLOT(sendMsg(QString)));
|
|
QObject::connect(w.getPrompt(), SIGNAL(returnPressed()), w.getPrompt(), SLOT(confirmationPerformed()));
|
|
w.show();
|
|
|
|
QObject::connect(&app, SIGNAL(aboutToQuit()), bot, SLOT(disconnect()));
|
|
|
|
sock.connectToServer(&app);
|
|
}
|
|
else
|
|
{
|
|
QCoreApplication coreApp(argc, argv);
|
|
|
|
QObject::connect(&coreApp, SIGNAL(aboutToQuit()), bot, SLOT(disconnect()));
|
|
|
|
sock.connectToServer(&coreApp);
|
|
}
|
|
delete(bot);
|
|
return 0;
|
|
}
|