began fixing regis bugs

This commit is contained in:
unknown 2015-06-05 15:40:12 +02:00
parent 60d86218eb
commit eb33a5f1f8
7 changed files with 41 additions and 36 deletions

View File

@ -1,12 +1,12 @@
QT += core gui network widgets
DESTDIR = $$bin_dir
DESTDIR = $$relative_path($$bin_dir)
TARGET = SparrowBot
TEMPLATE = app
CONFIG += c++11
LIBS += $$lib_dir/libircbot.a
LIBS += $$relative_path($$lib_dir/libircbot.a)
INCLUDEPATH += ../ircbot
SOURCES = main.cpp \

View File

@ -1,7 +1,7 @@
#include "regismodule.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)
{
@ -13,13 +13,13 @@ bool RegisModule::messageHandler(Message msg)
+ voc.getRandNom() + ".");
return true;
}
else if(msg.args.compare("!initrégis") == 0)
/*else if(msg.args.compare("!initrégis") == 0)
{
regisEnable = true;
setNick("il_est_con_Regis");
answer = QString("NICK %1\r\n").arg(getNick());
return true;
}
}*/
return false;
}

View File

@ -1,6 +1,7 @@
#include "vocab.h"
#include <time.h>
#include <QFile.h>
#include <QFile>
#include <QTextStream>
Vocab::Vocab()
{
@ -15,28 +16,30 @@ Vocab::Vocab(QString filename)
void Vocab::load(QString filename)
{
QFile file = QFile(filename);
if(file.isReadable())
file.open(QIODevice::ReadOnly);
if(file.isOpen())
QFile file(filename);
if(file.open(QIODevice::ReadOnly | QIODevice::Text))
{
char[512] buf;
int len;
while(len = file.readLine(buf, 512))
QTextStream stream(&file);
stream.setCodec("UTF-8");
for(QString line = stream.readLine(512);
line != QString::null;
line = stream.readLine(512))
{
if(len > 4)
if(line.length() > 2)
{
buf[len-1] = 0;
switch(buf[0])
line.remove(0, 2);
int firstChar = line.at(0).unicode();
switch(firstChar)
{
case 'n':
addNom(QString(buf+2));
case 'n' :
addNom(line);
break;
case 'v':
addVerbe(QString(buf+2));
case 'v' :
addVerbe(line);
break;
case 'a':
addAdjectif(QString(buf+2));
case 'a' :
addAdjectif(line);
break;
}
}
@ -47,20 +50,22 @@ void Vocab::load(QString filename)
void Vocab::save(QString filename)
{
QFile file = QFile(filename);
if(file.isWritable())
file.open(QIODevice::WriteOnly);
if(file.isOpen())
QFile file(filename);
if(file.open(QIODevice::WriteOnly | QIODevice::Text))
{
file.write(QString("#NOMS :\n"));
QTextStream stream(&file);
stream.setCodec("UTF-8");
stream << "#NOMS :\n";
for(QString n : noms)
file.write(QString("n:%1\n").arg(n));
file.write(QString("\n#VERBES :\n"));
stream << "n:" << n << "\n";
stream << "\n#VERBES :\n";
for(QString v : verbes)
file.write(QString("v:%1\n").arg(v));
file.write(QString("\n#ADJECTIFS :\n"));
stream << "v:" << v << "\n";
stream << "\n#ADJECTIFS :\n";
for(QString a : adjectifs)
file.write(QString("a:%1\n").arg(a));
stream << "a:" << a << "\n";
stream.flush();
file.close();
}
}

View File

@ -14,7 +14,7 @@ public:
Vocab(QString filename);
void load(QString filename);
void save(QString filename);
void merge(Vocab& voc);
void append(Vocab& voc);
void addNom(QString nom);
void addAdjectif(QString adj);

View File

@ -18,7 +18,7 @@ bool BaseModule::messageHandler(Message msg)
answer = "";
if(msg.command.compare("PING", Qt::CaseInsensitive) == 0)
{
answer = pong(msg.target);
answer = pong(msg.nick);
ret = true;
}
switch(status)

View File

@ -1,6 +1,6 @@
QT += core gui network widgets
DESTDIR = $$lib_dir
DESTDIR = $$relative_path($$lib_dir)
TARGET = ircbot

View File

@ -8,9 +8,9 @@ Message::Message(QString str)
if(str.startsWith("PING"))
{
command = "PING";
target = "PING";
nick = str.split(':')[1];
args = nick;
target = nick;
}
else
{