diff --git a/app/poilaumodule.cpp b/app/poilaumodule.cpp index 1f07902..967eeb3 100644 --- a/app/poilaumodule.cpp +++ b/app/poilaumodule.cpp @@ -1,73 +1,90 @@ #include "poilaumodule.h" #include "message.h" +#include +#include #define VOY_NONE -1 enum{VOY_A, VOY_E, VOY_I, VOY_O, VOY_U, VOY_ET, VOY_AI, VOY_OU, VOY_IN, VOY_ON, VOY_OI, VOY_EN, VOY_OUILLE}; bool PoilAuModule::messageHandler(Message msg) { + if(!isReady) + return false; if(msg.command.compare(QString("PRIVMSG"), Qt::CaseInsensitive) != 0) return false; int voy = VOY_NONE; + QString truncated = msg.args; + while(true) + { + if(truncated.size() == 1 || truncated.at(truncated.size()-1).isNumber()) + return false; + if(truncated.at(truncated.size()-1).isLetter() && truncated.at(truncated.size()-2).isLetter()) + break; + truncated.chop(1); + } - if(msg.args.endsWith("eu", Qt::CaseInsensitive)) + if(truncated.endsWith("eu", Qt::CaseInsensitive)) voy = VOY_E; - if(msg.args.endsWith("eux", Qt::CaseInsensitive)) + if(truncated.endsWith("eux", Qt::CaseInsensitive)) voy = VOY_E; - else if(msg.args.endsWith("au", Qt::CaseInsensitive)) + else if(truncated.endsWith("au", Qt::CaseInsensitive)) voy = VOY_O; - else if(msg.args.endsWith("ou", Qt::CaseInsensitive)) + else if(truncated.endsWith("ou", Qt::CaseInsensitive)) voy = VOY_OU; - else if(msg.args.endsWith("u", Qt::CaseInsensitive)) + else if(truncated.endsWith("où", Qt::CaseInsensitive)) + voy = VOY_OU; + else if(truncated.endsWith("u", Qt::CaseInsensitive)) voy = VOY_U; - if(msg.args.endsWith("oo", Qt::CaseInsensitive)) + if(truncated.endsWith("oo", Qt::CaseInsensitive)) voy = VOY_OU; - else if(msg.args.endsWith("o", Qt::CaseInsensitive)) + else if(truncated.endsWith("o", Qt::CaseInsensitive)) voy = VOY_O; - if(msg.args.endsWith("ait", Qt::CaseInsensitive)) + if(truncated.endsWith("ait", Qt::CaseInsensitive)) voy = VOY_AI; - if(msg.args.endsWith("ais", Qt::CaseInsensitive)) + if(truncated.endsWith("ais", Qt::CaseInsensitive)) voy = VOY_AI; - if(msg.args.endsWith("ai", Qt::CaseInsensitive)) + if(truncated.endsWith("ai", Qt::CaseInsensitive)) voy = VOY_AI; - else if(msg.args.endsWith("oi", Qt::CaseInsensitive)) + else if(truncated.endsWith("oi", Qt::CaseInsensitive)) voy = VOY_OI; - else if(msg.args.endsWith("i", Qt::CaseInsensitive)) + else if(truncated.endsWith("i", Qt::CaseInsensitive)) voy = VOY_I; - if(msg.args.endsWith("et", Qt::CaseInsensitive)) + if(truncated.endsWith("et", Qt::CaseInsensitive)) voy = VOY_ET; - if(msg.args.endsWith("é", Qt::CaseInsensitive)) + if(truncated.endsWith("é", Qt::CaseInsensitive)) voy = VOY_ET; - if(msg.args.endsWith("er", Qt::CaseInsensitive)) + if(truncated.endsWith("er", Qt::CaseInsensitive)) voy = VOY_ET; - if(msg.args.endsWith("è", Qt::CaseInsensitive)) + if(truncated.endsWith("è", Qt::CaseInsensitive)) voy = VOY_AI; - if(msg.args.endsWith("an", Qt::CaseInsensitive)) + if(truncated.endsWith("an", Qt::CaseInsensitive)) voy = VOY_EN; - if(msg.args.endsWith("en", Qt::CaseInsensitive)) + if(truncated.endsWith("en", Qt::CaseInsensitive)) voy = VOY_EN; - if(msg.args.endsWith("ment", Qt::CaseInsensitive)) + if(truncated.endsWith("ment", Qt::CaseInsensitive)) voy = VOY_EN; - if(msg.args.endsWith("in", Qt::CaseInsensitive)) + if(truncated.endsWith("in", Qt::CaseInsensitive)) voy = VOY_IN; - if(msg.args.endsWith("on", Qt::CaseInsensitive)) + if(truncated.endsWith("on", Qt::CaseInsensitive)) voy = VOY_ON; - if(msg.args.endsWith("ont", Qt::CaseInsensitive)) + if(truncated.endsWith("ont", Qt::CaseInsensitive)) voy = VOY_ON; - if(msg.args.endsWith("oie", Qt::CaseInsensitive)) + if(truncated.endsWith("oie", Qt::CaseInsensitive)) voy = VOY_OI; - if(msg.args.endsWith("ois", Qt::CaseInsensitive)) + if(truncated.endsWith("ois", Qt::CaseInsensitive)) voy = VOY_OI; - if(msg.args.endsWith("oit", Qt::CaseInsensitive)) + if(truncated.endsWith("oit", Qt::CaseInsensitive)) voy = VOY_OI; - if(msg.args.endsWith("a", Qt::CaseInsensitive)) + if(truncated.endsWith("a", Qt::CaseInsensitive)) + voy = VOY_A; + if(truncated.endsWith("à", Qt::CaseInsensitive)) voy = VOY_A; - if(msg.args.endsWith("ouille", Qt::CaseInsensitive)) + if(truncated.endsWith("ouille", Qt::CaseInsensitive)) voy = VOY_OUILLE; if(voy == VOY_NONE) @@ -115,6 +132,14 @@ bool PoilAuModule::messageHandler(Message msg) answer = say("Poil aux couilles."); break; } + isReady = false; + std::srand(time(NULL)); + int waitTime; + if(std::rand()%2) + waitTime = std::rand()%900000; // short (0 - 15 min) + else + waitTime = std::rand()%9000000; // long (15 min - 3 h) + QTimer::singleShot(waitTime, (QObject*)this, SLOT(setReady())); return true; } @@ -122,3 +147,13 @@ QString PoilAuModule::getName() { return "poilau"; } + +void PoilAuModule::setReady() +{ + isReady = true; +} + + + + + diff --git a/app/poilaumodule.h b/app/poilaumodule.h index 37da97f..8623654 100644 --- a/app/poilaumodule.h +++ b/app/poilaumodule.h @@ -1,13 +1,22 @@ #ifndef POILAUMODULE_H #define POILAUMODULE_H +#include #include "module.h" -class PoilAuModule : public Module +class PoilAuModule : public QObject, public Module { + Q_OBJECT + + bool isReady; public: + PoilAuModule() : isReady(true) {} + virtual bool messageHandler(Message msg); virtual QString getName(); + +public slots: + void setReady(); }; #endif // POILAUMODULE_H