added punisher module
This commit is contained in:
parent
ceac0efad1
commit
1f915cee59
@ -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
|
||||
|
@ -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();
|
||||
|
||||
|
59
app/punishermodule.cpp
Normal file
59
app/punishermodule.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
#include "punishermodule.h"
|
||||
#include "message.h"
|
||||
#include "user.h"
|
||||
#include <QStringList>
|
||||
|
||||
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(; i<str.size(); ++i)
|
||||
{
|
||||
forbidden_words.push_back(str[i]);
|
||||
answer += say(QString("added %1 to the list of forbidden words").arg(str[i]));
|
||||
}
|
||||
if(i==2)
|
||||
answer = say(QString("missing argument"));
|
||||
return true;
|
||||
}
|
||||
|
||||
if(msg.args.compare("!forbidden reset") == 0 && getUsers()->getFromNick(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");
|
||||
}
|
18
app/punishermodule.h
Normal file
18
app/punishermodule.h
Normal file
@ -0,0 +1,18 @@
|
||||
#ifndef PUNISHERMODULE_H
|
||||
#define PUNISHERMODULE_H
|
||||
|
||||
#include "module.h"
|
||||
#include <vector>
|
||||
|
||||
class PunisherModule : public Module
|
||||
{
|
||||
std::vector<QString> forbidden_words;
|
||||
|
||||
public:
|
||||
PunisherModule();
|
||||
|
||||
virtual bool messageHandler(Message msg);
|
||||
virtual QString getName();
|
||||
};
|
||||
|
||||
#endif // PUNISHERMODULE_H
|
@ -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");
|
||||
|
Loading…
x
Reference in New Issue
Block a user