From eb33a5f1f897eb7125cbb4ed82d4cfeb4ef02b05 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 5 Jun 2015 15:40:12 +0200 Subject: [PATCH] began fixing regis bugs --- app/app.pro | 4 +-- app/regismodule.cpp | 6 ++--- app/vocab.cpp | 59 +++++++++++++++++++++++-------------------- app/vocab.h | 2 +- ircbot/basemodule.cpp | 2 +- ircbot/ircbot.pro | 2 +- ircbot/message.cpp | 2 +- 7 files changed, 41 insertions(+), 36 deletions(-) diff --git a/app/app.pro b/app/app.pro index 5958ecc..6bc8b0c 100644 --- a/app/app.pro +++ b/app/app.pro @@ -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 \ diff --git a/app/regismodule.cpp b/app/regismodule.cpp index 8ba1a20..d7d4c98 100644 --- a/app/regismodule.cpp +++ b/app/regismodule.cpp @@ -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; } diff --git a/app/vocab.cpp b/app/vocab.cpp index 6c0d313..dfd2bc3 100644 --- a/app/vocab.cpp +++ b/app/vocab.cpp @@ -1,6 +1,7 @@ #include "vocab.h" #include -#include +#include +#include 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(); } } diff --git a/app/vocab.h b/app/vocab.h index caab934..08d3f70 100644 --- a/app/vocab.h +++ b/app/vocab.h @@ -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); diff --git a/ircbot/basemodule.cpp b/ircbot/basemodule.cpp index c16d793..c13d356 100644 --- a/ircbot/basemodule.cpp +++ b/ircbot/basemodule.cpp @@ -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) diff --git a/ircbot/ircbot.pro b/ircbot/ircbot.pro index 5d94d22..342c8c6 100644 --- a/ircbot/ircbot.pro +++ b/ircbot/ircbot.pro @@ -1,6 +1,6 @@ QT += core gui network widgets -DESTDIR = $$lib_dir +DESTDIR = $$relative_path($$lib_dir) TARGET = ircbot diff --git a/ircbot/message.cpp b/ircbot/message.cpp index c3ae9d4..f622d8a 100644 --- a/ircbot/message.cpp +++ b/ircbot/message.cpp @@ -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 {