From 1f915cee59da84f025894867ddee6d98c0c34367 Mon Sep 17 00:00:00 2001 From: Anselme Date: Mon, 20 Jun 2016 11:15:43 +0200 Subject: [PATCH] added punisher module --- app/app.pro | 6 +++-- app/main.cpp | 2 ++ app/punishermodule.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++ app/punishermodule.h | 18 +++++++++++++ app/sparrowmodule.cpp | 6 +++++ 5 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 app/punishermodule.cpp create mode 100644 app/punishermodule.h diff --git a/app/app.pro b/app/app.pro index f1c34b4..bf6ccd3 100644 --- a/app/app.pro +++ b/app/app.pro @@ -19,7 +19,8 @@ SOURCES = main.cpp \ todomodule.cpp \ jankenmodule.cpp \ janken.cpp \ - rpgmodule.cpp + rpgmodule.cpp \ + punishermodule.cpp HEADERS += \ regismodule.h \ @@ -31,4 +32,5 @@ HEADERS += \ todomodule.h \ jankenmodule.h \ janken.h \ - rpgmodule.h + rpgmodule.h \ + punishermodule.h diff --git a/app/main.cpp b/app/main.cpp index 3409e57..60acb53 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -11,6 +11,7 @@ #include "todomodule.h" #include "jankenmodule.h" #include "rpgmodule.h" +#include "punishermodule.h" // #include "janken.h" @@ -45,6 +46,7 @@ int main(int argc, char *argv[]) app.addModule(new FourasModule()); app.addModule(new JankenModule()); app.addModule(new RPGModule()); + app.addModule(new PunisherModule()); //app.addModule(new TodoModule()); return app.exec(); diff --git a/app/punishermodule.cpp b/app/punishermodule.cpp new file mode 100644 index 0000000..1f8e0d4 --- /dev/null +++ b/app/punishermodule.cpp @@ -0,0 +1,59 @@ +#include "punishermodule.h" +#include "message.h" +#include "user.h" +#include + +PunisherModule::PunisherModule() +{ + +} + +bool PunisherModule::messageHandler(Message msg) +{ + for(const QString &w : forbidden_words) + { + if(msg.args.contains(w)) + { + answer = QString("KICK %1\r\n").arg(msg.nick); + return true; + } + } + + if(msg.args.startsWith("!forbidden add ") && getUsers()->getFromNick(msg.nick)->isOp()) + { + QStringList str = msg.args.split(' '); + int i=2; + answer = QString(""); + for(; igetFromNick(msg.nick)->isOp()) + { + forbidden_words.clear(); + answer = say(QString("removed all forbidden words")); + return true; + } + + if(msg.args.compare("!forbidden list") == 0) + { + QString str = QString("Forbidden words are : "); + for(const QString &w : forbidden_words) + str.append(w).append(" "); + answer = say(str); + return true; + } + + return false; +} + +QString PunisherModule::getName() +{ + return QString("punisher"); +} diff --git a/app/punishermodule.h b/app/punishermodule.h new file mode 100644 index 0000000..584c7e8 --- /dev/null +++ b/app/punishermodule.h @@ -0,0 +1,18 @@ +#ifndef PUNISHERMODULE_H +#define PUNISHERMODULE_H + +#include "module.h" +#include + +class PunisherModule : public Module +{ + std::vector forbidden_words; + +public: + PunisherModule(); + + virtual bool messageHandler(Message msg); + virtual QString getName(); +}; + +#endif // PUNISHERMODULE_H diff --git a/app/sparrowmodule.cpp b/app/sparrowmodule.cpp index b338947..ea5df0c 100644 --- a/app/sparrowmodule.cpp +++ b/app/sparrowmodule.cpp @@ -44,6 +44,12 @@ bool SparrowModule::messageHandler(Message msg) answer = privateSay("available commands : !version, !bot, !devzone", msg.nick); return true; } + else if(msg.args.compare("!identify") == 0) + { + if(user->isOp()) + answer = privateSay(QString("IDENTIFY SparrowBot %2").arg(getPass()), "NickServ"); + return true; + } else if(msg.args.compare("re", Qt::CaseInsensitive) == 0) { answer = say("Re");