began fixing regis bugs
This commit is contained in:
parent
60d86218eb
commit
eb33a5f1f8
@ -1,12 +1,12 @@
|
|||||||
QT += core gui network widgets
|
QT += core gui network widgets
|
||||||
|
|
||||||
DESTDIR = $$bin_dir
|
DESTDIR = $$relative_path($$bin_dir)
|
||||||
|
|
||||||
TARGET = SparrowBot
|
TARGET = SparrowBot
|
||||||
TEMPLATE = app
|
TEMPLATE = app
|
||||||
CONFIG += c++11
|
CONFIG += c++11
|
||||||
|
|
||||||
LIBS += $$lib_dir/libircbot.a
|
LIBS += $$relative_path($$lib_dir/libircbot.a)
|
||||||
INCLUDEPATH += ../ircbot
|
INCLUDEPATH += ../ircbot
|
||||||
|
|
||||||
SOURCES = main.cpp \
|
SOURCES = main.cpp \
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include "regismodule.h"
|
#include "regismodule.h"
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
|
|
||||||
RegisModule::RegisModule() : voc("../res/vocab.txt"), regisEnable(false) {}
|
RegisModule::RegisModule() : voc("../res/vocab.txt"), regisEnable(true) {}
|
||||||
|
|
||||||
bool RegisModule::messageHandler(Message msg)
|
bool RegisModule::messageHandler(Message msg)
|
||||||
{
|
{
|
||||||
@ -13,13 +13,13 @@ bool RegisModule::messageHandler(Message msg)
|
|||||||
+ voc.getRandNom() + ".");
|
+ voc.getRandNom() + ".");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if(msg.args.compare("!initrégis") == 0)
|
/*else if(msg.args.compare("!initrégis") == 0)
|
||||||
{
|
{
|
||||||
regisEnable = true;
|
regisEnable = true;
|
||||||
setNick("il_est_con_Regis");
|
setNick("il_est_con_Regis");
|
||||||
answer = QString("NICK %1\r\n").arg(getNick());
|
answer = QString("NICK %1\r\n").arg(getNick());
|
||||||
return true;
|
return true;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "vocab.h"
|
#include "vocab.h"
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <QFile.h>
|
#include <QFile>
|
||||||
|
#include <QTextStream>
|
||||||
|
|
||||||
Vocab::Vocab()
|
Vocab::Vocab()
|
||||||
{
|
{
|
||||||
@ -15,28 +16,30 @@ Vocab::Vocab(QString filename)
|
|||||||
|
|
||||||
void Vocab::load(QString filename)
|
void Vocab::load(QString filename)
|
||||||
{
|
{
|
||||||
QFile file = QFile(filename);
|
QFile file(filename);
|
||||||
if(file.isReadable())
|
if(file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||||
file.open(QIODevice::ReadOnly);
|
|
||||||
if(file.isOpen())
|
|
||||||
{
|
{
|
||||||
char[512] buf;
|
QTextStream stream(&file);
|
||||||
int len;
|
stream.setCodec("UTF-8");
|
||||||
while(len = file.readLine(buf, 512))
|
|
||||||
|
for(QString line = stream.readLine(512);
|
||||||
|
line != QString::null;
|
||||||
|
line = stream.readLine(512))
|
||||||
{
|
{
|
||||||
if(len > 4)
|
if(line.length() > 2)
|
||||||
{
|
{
|
||||||
buf[len-1] = 0;
|
line.remove(0, 2);
|
||||||
switch(buf[0])
|
int firstChar = line.at(0).unicode();
|
||||||
|
switch(firstChar)
|
||||||
{
|
{
|
||||||
case 'n':
|
case 'n' :
|
||||||
addNom(QString(buf+2));
|
addNom(line);
|
||||||
break;
|
break;
|
||||||
case 'v':
|
case 'v' :
|
||||||
addVerbe(QString(buf+2));
|
addVerbe(line);
|
||||||
break;
|
break;
|
||||||
case 'a':
|
case 'a' :
|
||||||
addAdjectif(QString(buf+2));
|
addAdjectif(line);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -47,20 +50,22 @@ void Vocab::load(QString filename)
|
|||||||
|
|
||||||
void Vocab::save(QString filename)
|
void Vocab::save(QString filename)
|
||||||
{
|
{
|
||||||
QFile file = QFile(filename);
|
QFile file(filename);
|
||||||
if(file.isWritable())
|
if(file.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||||
file.open(QIODevice::WriteOnly);
|
|
||||||
if(file.isOpen())
|
|
||||||
{
|
{
|
||||||
file.write(QString("#NOMS :\n"));
|
QTextStream stream(&file);
|
||||||
|
stream.setCodec("UTF-8");
|
||||||
|
|
||||||
|
stream << "#NOMS :\n";
|
||||||
for(QString n : noms)
|
for(QString n : noms)
|
||||||
file.write(QString("n:%1\n").arg(n));
|
stream << "n:" << n << "\n";
|
||||||
file.write(QString("\n#VERBES :\n"));
|
stream << "\n#VERBES :\n";
|
||||||
for(QString v : verbes)
|
for(QString v : verbes)
|
||||||
file.write(QString("v:%1\n").arg(v));
|
stream << "v:" << v << "\n";
|
||||||
file.write(QString("\n#ADJECTIFS :\n"));
|
stream << "\n#ADJECTIFS :\n";
|
||||||
for(QString a : adjectifs)
|
for(QString a : adjectifs)
|
||||||
file.write(QString("a:%1\n").arg(a));
|
stream << "a:" << a << "\n";
|
||||||
|
stream.flush();
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ public:
|
|||||||
Vocab(QString filename);
|
Vocab(QString filename);
|
||||||
void load(QString filename);
|
void load(QString filename);
|
||||||
void save(QString filename);
|
void save(QString filename);
|
||||||
void merge(Vocab& voc);
|
void append(Vocab& voc);
|
||||||
|
|
||||||
void addNom(QString nom);
|
void addNom(QString nom);
|
||||||
void addAdjectif(QString adj);
|
void addAdjectif(QString adj);
|
||||||
|
@ -18,7 +18,7 @@ bool BaseModule::messageHandler(Message msg)
|
|||||||
answer = "";
|
answer = "";
|
||||||
if(msg.command.compare("PING", Qt::CaseInsensitive) == 0)
|
if(msg.command.compare("PING", Qt::CaseInsensitive) == 0)
|
||||||
{
|
{
|
||||||
answer = pong(msg.target);
|
answer = pong(msg.nick);
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
switch(status)
|
switch(status)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
QT += core gui network widgets
|
QT += core gui network widgets
|
||||||
|
|
||||||
DESTDIR = $$lib_dir
|
DESTDIR = $$relative_path($$lib_dir)
|
||||||
|
|
||||||
TARGET = ircbot
|
TARGET = ircbot
|
||||||
|
|
||||||
|
@ -8,9 +8,9 @@ Message::Message(QString str)
|
|||||||
if(str.startsWith("PING"))
|
if(str.startsWith("PING"))
|
||||||
{
|
{
|
||||||
command = "PING";
|
command = "PING";
|
||||||
target = "PING";
|
|
||||||
nick = str.split(':')[1];
|
nick = str.split(':')[1];
|
||||||
args = nick;
|
args = nick;
|
||||||
|
target = nick;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user