From 47ff21f565019d341e6967d3350024b4cc03b256 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 5 Jun 2015 16:37:36 +0200 Subject: [PATCH] fixed some things --- app/app.pro | 4 ++-- app/regismodule.cpp | 9 +++++---- app/vocab.cpp | 9 +++++++-- ircbot/ircbot.pro | 2 +- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/app.pro b/app/app.pro index 6bc8b0c..5958ecc 100644 --- a/app/app.pro +++ b/app/app.pro @@ -1,12 +1,12 @@ QT += core gui network widgets -DESTDIR = $$relative_path($$bin_dir) +DESTDIR = $$bin_dir TARGET = SparrowBot TEMPLATE = app CONFIG += c++11 -LIBS += $$relative_path($$lib_dir/libircbot.a) +LIBS += $$lib_dir/libircbot.a INCLUDEPATH += ../ircbot SOURCES = main.cpp \ diff --git a/app/regismodule.cpp b/app/regismodule.cpp index d7d4c98..1b285a3 100644 --- a/app/regismodule.cpp +++ b/app/regismodule.cpp @@ -1,11 +1,11 @@ #include "regismodule.h" #include "message.h" -RegisModule::RegisModule() : voc("../res/vocab.txt"), regisEnable(true) {} +RegisModule::RegisModule() : regisEnable(false) {} bool RegisModule::messageHandler(Message msg) { - if(msg.args.contains("régis ?")) + if(msg.args.contains("régis ?") && regisEnable) { answer = say(voc.getRandNom() + " " + voc.getRandAdjectif() + " " @@ -13,13 +13,14 @@ 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; + voc.load("../res/vocab.txt"); 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 dfd2bc3..960e227 100644 --- a/app/vocab.cpp +++ b/app/vocab.cpp @@ -2,6 +2,7 @@ #include #include #include +#include Vocab::Vocab() { @@ -17,8 +18,12 @@ Vocab::Vocab(QString filename) void Vocab::load(QString filename) { QFile file(filename); - if(file.open(QIODevice::ReadOnly | QIODevice::Text)) + if(!file.exists()) + std::cerr << "can't find " << filename << std::endl; + else if(file.open(QIODevice::ReadOnly | QIODevice::Text)) { + std::cerr << "file is open" << std::endl; + QTextStream stream(&file); stream.setCodec("UTF-8"); @@ -28,8 +33,8 @@ void Vocab::load(QString filename) { if(line.length() > 2) { - line.remove(0, 2); int firstChar = line.at(0).unicode(); + line.remove(0, 2); switch(firstChar) { case 'n' : diff --git a/ircbot/ircbot.pro b/ircbot/ircbot.pro index 342c8c6..5d94d22 100644 --- a/ircbot/ircbot.pro +++ b/ircbot/ircbot.pro @@ -1,6 +1,6 @@ QT += core gui network widgets -DESTDIR = $$relative_path($$lib_dir) +DESTDIR = $$lib_dir TARGET = ircbot