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
|
||||
*.Release
|
||||
Makefile
|
||||
ui_*
|
@ -1,4 +1,6 @@
|
||||
#include "basemodule.h"
|
||||
#include "message.h"
|
||||
#include <QStringList>
|
||||
|
||||
BaseModule::BaseModule() : Module(), status(OFFLINE)
|
||||
{
|
||||
@ -7,38 +9,47 @@ BaseModule::BaseModule() : Module(), status(OFFLINE)
|
||||
|
||||
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)
|
||||
{
|
||||
case OFFLINE :
|
||||
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;
|
||||
case ONLINE :
|
||||
if(str.contains("PING"))
|
||||
if(msg.command.compare("376") == 0)
|
||||
{
|
||||
status = ON_CHAN;
|
||||
emit sendMsg(pong(msg.nick));
|
||||
emit sendMsg(join(getChan()));
|
||||
answer += join(getChan());
|
||||
ret = true;
|
||||
}
|
||||
break;
|
||||
case ON_CHAN :
|
||||
if(str.contains("PING"))
|
||||
answer = pong(msg.nick);
|
||||
return onChanHandler(msg);
|
||||
ret |= onChanHandler(msg);
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool BaseModule::onChanHandler(Message msg)
|
||||
{
|
||||
bool ret = false;
|
||||
User* src = users.getFromNick(msg.nick);
|
||||
|
||||
// si la ligne est un message
|
||||
if(msg.command.compare(QString("PRIVMSG"), Qt::CaseInsensitive) == 0)
|
||||
{
|
||||
// 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;
|
||||
}
|
||||
|
||||
@ -53,23 +64,23 @@ bool BaseModule::onChanHandler(Message msg)
|
||||
str.append(u->getNick());
|
||||
str.append(" ");
|
||||
}
|
||||
answer = say(str);
|
||||
answer += say(str);
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
|
||||
// renommage
|
||||
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)
|
||||
users.remove(msg.src);
|
||||
users.remove(src);
|
||||
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)
|
||||
{
|
||||
if(getNick().compare(msg.target2) == 0)
|
||||
{
|
||||
answer = quit("i've been kicked :(");
|
||||
answer += quit("i've been kicked :(");
|
||||
ret = true;
|
||||
}
|
||||
users.remove(users.getFromNick(msg.target2));
|
||||
@ -78,9 +89,9 @@ bool BaseModule::onChanHandler(Message msg)
|
||||
&& msg.args.contains(getChan())
|
||||
&& getNick().compare(msg.nick) != 0)
|
||||
{
|
||||
users.getOrAdd(msg.nick);
|
||||
answer = whois(msg.nick);
|
||||
ret = true;
|
||||
users.getOrAdd(msg.nick);
|
||||
answer += whois(msg.nick);
|
||||
ret = true;
|
||||
}
|
||||
|
||||
// 353 = code de la ligne qui liste les nicks connectés
|
||||
@ -92,7 +103,7 @@ bool BaseModule::onChanHandler(Message msg)
|
||||
for(QString s : names)
|
||||
{
|
||||
users.getOrAdd(s);
|
||||
answer = whois(s);
|
||||
answer += whois(s);
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
|
@ -59,10 +59,10 @@ int BotApp::exec()
|
||||
if(!nogui)
|
||||
{
|
||||
window = new MainWindow();
|
||||
QObject::connect(sock, SIGNAL(receivedMsg(QString)), window->getConsole(), 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()));
|
||||
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);
|
||||
|
4
botapp.h
4
botapp.h
@ -8,10 +8,8 @@ class IRCBot;
|
||||
class SocketIRC;
|
||||
class MainWindow;
|
||||
|
||||
class BotApp : public QObject
|
||||
class BotApp
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
bool nogui = false;
|
||||
QString server = "irc.freenode.net";
|
||||
int port = 6667;
|
||||
|
@ -13,7 +13,7 @@ void IRCBot::receiveMsg(QString str)
|
||||
|
||||
for(Module* m : modules)
|
||||
{
|
||||
if(m->messageHandler(msg))
|
||||
if(m->isEnabled() && m->messageHandler(msg))
|
||||
emit sendMsg(m->getAnswer());
|
||||
}
|
||||
}
|
||||
|
14
main.cpp
14
main.cpp
@ -4,14 +4,20 @@
|
||||
|
||||
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";
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
#include <QTextBrowser>
|
||||
#include "prompt.h"
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
|
@ -5,9 +5,6 @@
|
||||
|
||||
class Prompt;
|
||||
class QTextBrowser;
|
||||
class QSlider;
|
||||
class QProgressBar;
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
}
|
||||
@ -21,8 +18,6 @@ public:
|
||||
~MainWindow();
|
||||
|
||||
QTextBrowser* getConsole();
|
||||
QSlider* getSwitch();
|
||||
QProgressBar* getLed();
|
||||
Prompt* getPrompt();
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
|
4
module.h
4
module.h
@ -26,8 +26,8 @@ protected:
|
||||
public:
|
||||
Module() : enabled(true) {}
|
||||
|
||||
virtual bool messageHandler(Message msg);
|
||||
virtual QString getName();
|
||||
virtual bool messageHandler(Message msg) = 0;
|
||||
virtual QString getName() = 0;
|
||||
|
||||
QString getAnswer();
|
||||
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