debugged most of the features of the module version
This commit is contained in:
parent
09c0ab5b56
commit
4aac5b2bb4
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,3 +5,4 @@ release/*
|
|||||||
*.Debug
|
*.Debug
|
||||||
*.Release
|
*.Release
|
||||||
Makefile
|
Makefile
|
||||||
|
ui_*
|
@ -1,4 +1,6 @@
|
|||||||
#include "basemodule.h"
|
#include "basemodule.h"
|
||||||
|
#include "message.h"
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
BaseModule::BaseModule() : Module(), status(OFFLINE)
|
BaseModule::BaseModule() : Module(), status(OFFLINE)
|
||||||
{
|
{
|
||||||
@ -7,38 +9,47 @@ BaseModule::BaseModule() : Module(), status(OFFLINE)
|
|||||||
|
|
||||||
bool BaseModule::messageHandler(Message msg)
|
bool BaseModule::messageHandler(Message msg)
|
||||||
{
|
{
|
||||||
|
bool ret = false;
|
||||||
|
answer = "";
|
||||||
|
if(msg.command.compare("PING", Qt::CaseInsensitive) == 0)
|
||||||
|
{
|
||||||
|
answer = pong(msg.target);
|
||||||
|
ret = true;
|
||||||
|
}
|
||||||
switch(status)
|
switch(status)
|
||||||
{
|
{
|
||||||
case OFFLINE :
|
case OFFLINE :
|
||||||
status = ONLINE;
|
status = ONLINE;
|
||||||
emit sendMsg(QString("NICK %1\r\nUSER %2 0 * %3").arg(getNick()).arg(getNick()).arg(getNick()));
|
answer = QString("NICK %1\r\nUSER %2 0 * %3\r\n").arg(getNick()).arg(getNick()).arg(getNick());
|
||||||
|
ret = true;
|
||||||
break;
|
break;
|
||||||
case ONLINE :
|
case ONLINE :
|
||||||
if(str.contains("PING"))
|
if(msg.command.compare("376") == 0)
|
||||||
{
|
{
|
||||||
status = ON_CHAN;
|
status = ON_CHAN;
|
||||||
emit sendMsg(pong(msg.nick));
|
answer += join(getChan());
|
||||||
emit sendMsg(join(getChan()));
|
ret = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ON_CHAN :
|
case ON_CHAN :
|
||||||
if(str.contains("PING"))
|
ret |= onChanHandler(msg);
|
||||||
answer = pong(msg.nick);
|
|
||||||
return onChanHandler(msg);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BaseModule::onChanHandler(Message msg)
|
bool BaseModule::onChanHandler(Message msg)
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
User* src = users.getFromNick(msg.nick);
|
||||||
|
|
||||||
// si la ligne est un message
|
// si la ligne est un message
|
||||||
if(msg.command.compare(QString("PRIVMSG"), Qt::CaseInsensitive) == 0)
|
if(msg.command.compare(QString("PRIVMSG"), Qt::CaseInsensitive) == 0)
|
||||||
{
|
{
|
||||||
// mise à jour du bot
|
// mise à jour du bot
|
||||||
if(msg.args.compare("!update") == 0 && msg.src != NULL && msg.src->isOp())
|
if(msg.args.compare("!update") == 0 && src != NULL && src->isOp())
|
||||||
{
|
{
|
||||||
answer = quit("Rebooting for update...");
|
answer += quit("Rebooting for update...");
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,23 +64,23 @@ bool BaseModule::onChanHandler(Message msg)
|
|||||||
str.append(u->getNick());
|
str.append(u->getNick());
|
||||||
str.append(" ");
|
str.append(" ");
|
||||||
}
|
}
|
||||||
answer = say(str);
|
answer += say(str);
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// renommage
|
// renommage
|
||||||
else if(msg.command.compare("NICK", Qt::CaseInsensitive) == 0)
|
else if(msg.command.compare("NICK", Qt::CaseInsensitive) == 0)
|
||||||
msg.src->rename(msg.args);
|
src->rename(msg.args);
|
||||||
else if(msg.command.compare("QUIT", Qt::CaseInsensitive) == 0)
|
else if(msg.command.compare("QUIT", Qt::CaseInsensitive) == 0)
|
||||||
users.remove(msg.src);
|
users.remove(src);
|
||||||
else if(msg.command.compare("PART", Qt::CaseInsensitive) == 0)
|
else if(msg.command.compare("PART", Qt::CaseInsensitive) == 0)
|
||||||
users.remove(msg.src);
|
users.remove(src);
|
||||||
else if(msg.command.compare("KICK", Qt::CaseInsensitive) == 0)
|
else if(msg.command.compare("KICK", Qt::CaseInsensitive) == 0)
|
||||||
{
|
{
|
||||||
if(getNick().compare(msg.target2) == 0)
|
if(getNick().compare(msg.target2) == 0)
|
||||||
{
|
{
|
||||||
answer = quit("i've been kicked :(");
|
answer += quit("i've been kicked :(");
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
users.remove(users.getFromNick(msg.target2));
|
users.remove(users.getFromNick(msg.target2));
|
||||||
@ -78,9 +89,9 @@ bool BaseModule::onChanHandler(Message msg)
|
|||||||
&& msg.args.contains(getChan())
|
&& msg.args.contains(getChan())
|
||||||
&& getNick().compare(msg.nick) != 0)
|
&& getNick().compare(msg.nick) != 0)
|
||||||
{
|
{
|
||||||
users.getOrAdd(msg.nick);
|
users.getOrAdd(msg.nick);
|
||||||
answer = whois(msg.nick);
|
answer += whois(msg.nick);
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 353 = code de la ligne qui liste les nicks connectés
|
// 353 = code de la ligne qui liste les nicks connectés
|
||||||
@ -92,7 +103,7 @@ bool BaseModule::onChanHandler(Message msg)
|
|||||||
for(QString s : names)
|
for(QString s : names)
|
||||||
{
|
{
|
||||||
users.getOrAdd(s);
|
users.getOrAdd(s);
|
||||||
answer = whois(s);
|
answer += whois(s);
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,10 +59,10 @@ int BotApp::exec()
|
|||||||
if(!nogui)
|
if(!nogui)
|
||||||
{
|
{
|
||||||
window = new MainWindow();
|
window = new MainWindow();
|
||||||
QObject::connect(sock, SIGNAL(receivedMsg(QString)), window->getConsole(), SLOT(append(QString)));
|
QObject::connect(sock, SIGNAL(receivedMsg(QString)), (QObject*)window->getConsole(), SLOT(append(QString)));
|
||||||
QObject::connect(bot, SIGNAL(sendMsg(QString)), window->getConsole(), SLOT(append(QString)));
|
QObject::connect(bot, SIGNAL(sendMsg(QString)), (QObject*)window->getConsole(), SLOT(append(QString)));
|
||||||
QObject::connect(window->getPrompt(), SIGNAL(sendMsg(QString)), sock, SLOT(sendMsg(QString)));
|
QObject::connect((QObject*)window->getPrompt(), SIGNAL(sendMsg(QString)), sock, SLOT(sendMsg(QString)));
|
||||||
QObject::connect(window->getPrompt(), SIGNAL(returnPressed()), window->getPrompt(), SLOT(confirmationPerformed()));
|
QObject::connect((QObject*)window->getPrompt(), SIGNAL(returnPressed()), (QObject*)window->getPrompt(), SLOT(confirmationPerformed()));
|
||||||
window->show();
|
window->show();
|
||||||
}
|
}
|
||||||
return sock->connectToServer(coreApp);
|
return sock->connectToServer(coreApp);
|
||||||
|
4
botapp.h
4
botapp.h
@ -8,10 +8,8 @@ class IRCBot;
|
|||||||
class SocketIRC;
|
class SocketIRC;
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
|
|
||||||
class BotApp : public QObject
|
class BotApp
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
bool nogui = false;
|
bool nogui = false;
|
||||||
QString server = "irc.freenode.net";
|
QString server = "irc.freenode.net";
|
||||||
int port = 6667;
|
int port = 6667;
|
||||||
|
@ -13,7 +13,7 @@ void IRCBot::receiveMsg(QString str)
|
|||||||
|
|
||||||
for(Module* m : modules)
|
for(Module* m : modules)
|
||||||
{
|
{
|
||||||
if(m->messageHandler(msg))
|
if(m->isEnabled() && m->messageHandler(msg))
|
||||||
emit sendMsg(m->getAnswer());
|
emit sendMsg(m->getAnswer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
14
main.cpp
14
main.cpp
@ -4,14 +4,20 @@
|
|||||||
|
|
||||||
class CustomModule : public Module
|
class CustomModule : public Module
|
||||||
{
|
{
|
||||||
CustomModule() : Module(), answer("coucou") {}
|
public :
|
||||||
|
CustomModule() : Module() {}
|
||||||
|
|
||||||
bool messageHandler(Message msg)
|
virtual bool messageHandler(Message msg)
|
||||||
{
|
{
|
||||||
return msg.args.compare("plop ?") == 0;
|
if(msg.args.compare("plop ?") == 0)
|
||||||
|
{
|
||||||
|
answer = say("coucou");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString getName()
|
virtual QString getName()
|
||||||
{
|
{
|
||||||
return "custom";
|
return "custom";
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
|
#include <QTextBrowser>
|
||||||
|
#include "prompt.h"
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent) :
|
MainWindow::MainWindow(QWidget *parent) :
|
||||||
QMainWindow(parent),
|
QMainWindow(parent),
|
||||||
|
@ -5,9 +5,6 @@
|
|||||||
|
|
||||||
class Prompt;
|
class Prompt;
|
||||||
class QTextBrowser;
|
class QTextBrowser;
|
||||||
class QSlider;
|
|
||||||
class QProgressBar;
|
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
}
|
}
|
||||||
@ -21,8 +18,6 @@ public:
|
|||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
|
||||||
QTextBrowser* getConsole();
|
QTextBrowser* getConsole();
|
||||||
QSlider* getSwitch();
|
|
||||||
QProgressBar* getLed();
|
|
||||||
Prompt* getPrompt();
|
Prompt* getPrompt();
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
|
4
module.h
4
module.h
@ -26,8 +26,8 @@ protected:
|
|||||||
public:
|
public:
|
||||||
Module() : enabled(true) {}
|
Module() : enabled(true) {}
|
||||||
|
|
||||||
virtual bool messageHandler(Message msg);
|
virtual bool messageHandler(Message msg) = 0;
|
||||||
virtual QString getName();
|
virtual QString getName() = 0;
|
||||||
|
|
||||||
QString getAnswer();
|
QString getAnswer();
|
||||||
bool isEnabled();
|
bool isEnabled();
|
||||||
|
@ -1,74 +0,0 @@
|
|||||||
/********************************************************************************
|
|
||||||
** Form generated from reading UI file 'mainwindow.ui'
|
|
||||||
**
|
|
||||||
** Created by: Qt User Interface Compiler version 5.4.1
|
|
||||||
**
|
|
||||||
** WARNING! All changes made in this file will be lost when recompiling UI file!
|
|
||||||
********************************************************************************/
|
|
||||||
|
|
||||||
#ifndef UI_MAINWINDOW_H
|
|
||||||
#define UI_MAINWINDOW_H
|
|
||||||
|
|
||||||
#include <QtCore/QVariant>
|
|
||||||
#include <QtWidgets/QAction>
|
|
||||||
#include <QtWidgets/QApplication>
|
|
||||||
#include <QtWidgets/QButtonGroup>
|
|
||||||
#include <QtWidgets/QGridLayout>
|
|
||||||
#include <QtWidgets/QHeaderView>
|
|
||||||
#include <QtWidgets/QMainWindow>
|
|
||||||
#include <QtWidgets/QTextBrowser>
|
|
||||||
#include <QtWidgets/QWidget>
|
|
||||||
#include "prompt.h"
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
|
||||||
|
|
||||||
class Ui_MainWindow
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
QWidget *centralWidget;
|
|
||||||
QGridLayout *gridLayout;
|
|
||||||
QTextBrowser *monitoringConsole;
|
|
||||||
Prompt *prompt;
|
|
||||||
|
|
||||||
void setupUi(QMainWindow *MainWindow)
|
|
||||||
{
|
|
||||||
if (MainWindow->objectName().isEmpty())
|
|
||||||
MainWindow->setObjectName(QStringLiteral("MainWindow"));
|
|
||||||
MainWindow->resize(374, 404);
|
|
||||||
centralWidget = new QWidget(MainWindow);
|
|
||||||
centralWidget->setObjectName(QStringLiteral("centralWidget"));
|
|
||||||
gridLayout = new QGridLayout(centralWidget);
|
|
||||||
gridLayout->setSpacing(6);
|
|
||||||
gridLayout->setContentsMargins(11, 11, 11, 11);
|
|
||||||
gridLayout->setObjectName(QStringLiteral("gridLayout"));
|
|
||||||
monitoringConsole = new QTextBrowser(centralWidget);
|
|
||||||
monitoringConsole->setObjectName(QStringLiteral("monitoringConsole"));
|
|
||||||
|
|
||||||
gridLayout->addWidget(monitoringConsole, 1, 0, 1, 2);
|
|
||||||
|
|
||||||
prompt = new Prompt(centralWidget);
|
|
||||||
prompt->setObjectName(QStringLiteral("prompt"));
|
|
||||||
|
|
||||||
gridLayout->addWidget(prompt, 0, 0, 1, 2);
|
|
||||||
|
|
||||||
MainWindow->setCentralWidget(centralWidget);
|
|
||||||
|
|
||||||
retranslateUi(MainWindow);
|
|
||||||
|
|
||||||
QMetaObject::connectSlotsByName(MainWindow);
|
|
||||||
} // setupUi
|
|
||||||
|
|
||||||
void retranslateUi(QMainWindow *MainWindow)
|
|
||||||
{
|
|
||||||
MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0));
|
|
||||||
} // retranslateUi
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace Ui {
|
|
||||||
class MainWindow: public Ui_MainWindow {};
|
|
||||||
} // namespace Ui
|
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
|
||||||
|
|
||||||
#endif // UI_MAINWINDOW_H
|
|
Loading…
x
Reference in New Issue
Block a user