diff --git a/.gitignore b/.gitignore index 14f331c..3087d07 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ debug/* release/* *.user *.Debug -*.Release \ No newline at end of file +*.Release +Makefile diff --git a/SparrowBot.pro b/SparrowBot.pro index fa18909..3a23cf0 100644 --- a/SparrowBot.pro +++ b/SparrowBot.pro @@ -10,19 +10,20 @@ TARGET = SparrowBot TEMPLATE = app CONFIG += c++11 -SOURCES += main.cpp\ - mainwindow.cpp \ - sparrowbot.cpp \ +SOURCES += mainwindow.cpp \ socketirc.cpp \ message.cpp \ user.cpp \ - prompt.cpp + prompt.cpp \ + ircbot.cpp \ + botapp.cpp -HEADERS += mainwindow.h \ - sparrowbot.h \ +HEADERS += mainwindow.h \ socketirc.h \ message.h \ user.h \ - prompt.h + prompt.h \ + ircbot.h \ + botapp.h FORMS += mainwindow.ui diff --git a/botapp.cpp b/botapp.cpp new file mode 100644 index 0000000..b43eeec --- /dev/null +++ b/botapp.cpp @@ -0,0 +1,72 @@ +#include "botapp.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; igetConsole(), SLOT(append(QString))); + QObject::connect(bot, SIGNAL(sendMsg(QString)), window->getConsole(), SLOT(append(QString))); + QObject::connect(window->getPrompt(), SIGNAL(sendMsg(QString)), sock, SLOT(sendMsg(QString))); + QObject::connect(window->getPrompt(), SIGNAL(returnPressed()), window->getPrompt(), SLOT(confirmationPerformed())); + window->show(); + } + return sock->connectToServer(coreApp); +} + +int main(int argc, char *argv[]) +{ + BotApp app = BotApp(argc, argv); + return app.exec(); +} diff --git a/botapp.h b/botapp.h new file mode 100644 index 0000000..2797870 --- /dev/null +++ b/botapp.h @@ -0,0 +1,28 @@ +#ifndef BOTAPP_H +#define BOTAPP_H + +#include "mainwindow.h" +#include "socketirc.h" +#include "ircbot.h" +#include + +class BotApp +{ + bool nogui = false; + QString server = "irc.freenode.net"; + int port = 6667; + QString nick = "SparrowBotDebug"; + QString chan = "epicsparrow"; + + SocketIRC* sock; + IRCBot* bot; + QCoreApplication* coreApp; + MainWindow* window; + +public: + BotApp(int argc, char** argv); + ~BotApp(); + int exec(); +}; + +#endif // BOTAPP_H diff --git a/sparrowbot.cpp b/ircbot.cpp similarity index 88% rename from sparrowbot.cpp rename to ircbot.cpp index 0a9332d..032d0e0 100644 --- a/sparrowbot.cpp +++ b/ircbot.cpp @@ -1,11 +1,11 @@ -#include "sparrowbot.h" +#include "ircbot.h" #include #include #include using namespace std; -void SparrowBot::receiveMsg(QString str) +void IRCBot::receiveMsg(QString str) { Message msg = Message(str, &users); @@ -31,7 +31,7 @@ void SparrowBot::receiveMsg(QString str) } } -void SparrowBot::handleMessage(Message msg) +void IRCBot::handleMessage(Message msg) { // si la ligne est un message if(msg.command.compare(QString("PRIVMSG"), Qt::CaseInsensitive) == 0) @@ -105,42 +105,42 @@ void SparrowBot::handleMessage(Message msg) } } -QString SparrowBot::pong(QString target) +QString IRCBot::pong(QString target) { return QString("PONG :%1").arg(target); } -QString SparrowBot::join(QString theChan) +QString IRCBot::join(QString theChan) { return QString("JOIN #%1").arg(theChan); } -QString SparrowBot::whois(QString nick) +QString IRCBot::whois(QString nick) { return QString("WHOIS %1").arg(nick); } -QString SparrowBot::say(QString str) +QString IRCBot::say(QString str) { return QString("PRIVMSG #%1 :%2").arg(chan).arg(str); } -QString SparrowBot::privateSay(QString str, QString target) +QString IRCBot::privateSay(QString str, QString target) { return QString("PRIVMSG %1 :%2").arg(target).arg(str); } -QString SparrowBot::action(QString str) +QString IRCBot::action(QString str) { return QString("PRIVMSG #%1 :\001ACTION %2\001").arg(chan).arg(str); } -QString SparrowBot::quit(QString str) +QString IRCBot::quit(QString str) { return QString("QUIT :%1").arg(str); } -void SparrowBot::disconnect() +void IRCBot::disconnect() { emit sendMsg(quit("I'll be back")); } diff --git a/sparrowbot.h b/ircbot.h similarity index 76% rename from sparrowbot.h rename to ircbot.h index 698de36..59ef5c6 100644 --- a/sparrowbot.h +++ b/ircbot.h @@ -1,11 +1,11 @@ -#ifndef SPARROWBOT_H -#define SPARROWBOT_H +#ifndef IRCBOT_H +#define IRCBOT_H #include "user.h" #include "message.h" #include -class SparrowBot : public QObject +class IRCBot : public QObject { Q_OBJECT @@ -17,11 +17,12 @@ class SparrowBot : public QObject UserList users; public: - SparrowBot(QString nick_, QString chan_) : nick(nick_), chan(chan_), status(OFFLINE) {} + IRCBot(QString nick_, QString chan_) : nick(nick_), chan(chan_), status(OFFLINE) {} private: void handleMessage(Message msg); +protected: // IRC commands QString pong(QString target); QString join(QString theChan); @@ -39,4 +40,4 @@ signals: void sendMsg(QString msg); }; -#endif // SPARROWBOT_H +#endif // IRCBOT_H diff --git a/main.cpp b/main.cpp deleted file mode 100644 index 44f00d4..0000000 --- a/main.cpp +++ /dev/null @@ -1,75 +0,0 @@ -#include "mainwindow.h" -#include "socketirc.h" -#include "sparrowbot.h" -#include - -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; iexit(); else - exit(0); + return 0; } - app->exec(); + return app->exec(); } void SocketIRC::readMsg() diff --git a/socketirc.h b/socketirc.h index 7035c41..3a50630 100644 --- a/socketirc.h +++ b/socketirc.h @@ -16,7 +16,7 @@ public: SocketIRC(QString server_, int port_); void setServer(QString server_); void setPort(int port_); - void connectToServer(QCoreApplication* app_); + int connectToServer(QCoreApplication* app_); private: