added sparrow module

This commit is contained in:
Anselme 2015-05-31 01:01:34 +02:00
parent 6ff62f34b3
commit 19c7f7631f
5 changed files with 60 additions and 9 deletions

View File

@ -10,7 +10,9 @@ release:LIBS += ../ircbot/release/libircbot.a
INCLUDEPATH += ../ircbot
SOURCES = main.cpp \
regismodule.cpp
regismodule.cpp \
sparrowmodule.cpp
HEADERS += \
regismodule.h
regismodule.h \
sparrowmodule.h

View File

@ -3,6 +3,7 @@
#include "message.h"
#include "basemodule.h"
#include "regismodule.h"
#include "sparrowmodule.h"
class CustomModule : public Module
{
@ -30,5 +31,6 @@ int main(int argc, char *argv[])
BotApp app = BotApp(argc, argv);
app.addModule(new CustomModule());
app.addModule(new RegisModule());
app.addModule(new SparrowModule());
return app.exec();
}

24
app/sparrowmodule.cpp Normal file
View File

@ -0,0 +1,24 @@
#include "sparrowmodule.h"
#include "message.h"
SparrowModule::SparrowModule()
{
}
bool SparrowModule::messageHandler(Message msg)
{
if(msg.command.compare("JOIN") == 0
&& msg.target.compare("#"+getChan()) == 0
&& msg.nick.compare(getNick()) != 0)
{
answer = say("Bienvenue sur #epicsparrow "+msg.nick+"!");
return true;
}
return false;
}
QString SparrowModule::getName()
{
return "sparrow";
}

14
app/sparrowmodule.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef SPARROWMODULE_H
#define SPARROWMODULE_H
#include "module.h"
class SparrowModule : public Module
{
public:
SparrowModule();
virtual bool messageHandler(Message msg);
virtual QString getName();
};
#endif // SPARROWMODULE_H

View File

@ -103,16 +103,25 @@ bool BaseModule::onChanHandler(Message msg)
{
bool newStatus = command.compare("enable") == 0;
for(int i=2; i<list.size(); ++i)
for(int j=1; j<getNbModules(); ++j)
{
Module* m = getModule(j);
if(m->getName().compare(list[i]) == 0)
bool found = false;
if(list[i].compare("base") == 0)
{
if(m->isEnabled() != newStatus)
answer += say((newStatus ? "enabled module " : "disabled module ") + list[i]);
m->setEnabled(newStatus);
answer += say("base module must stay enabled");
continue;
}
else
for(int j=1; j<getNbModules(); ++j)
{
Module* m = getModule(j);
if(m->getName().compare(list[i]) == 0)
{
if(m->isEnabled() != newStatus)
answer += say((newStatus ? "enabled module " : "disabled module ") + list[i]);
m->setEnabled(newStatus);
found = true;
}
}
if(!found)
answer += say("no module named " + list[i]);
}
ret = true;