todo module command parsing works
This commit is contained in:
parent
085d5cd193
commit
32aa05de42
@ -6,6 +6,7 @@
|
||||
#include "sparrowmodule.h"
|
||||
#include "poilaumodule.h"
|
||||
#include "fourasmodule.h"
|
||||
#include "todomodule.h"
|
||||
|
||||
class HelloWorldModule : public Module
|
||||
{
|
||||
@ -36,5 +37,6 @@ int main(int argc, char *argv[])
|
||||
app.addModule(new SparrowModule());
|
||||
app.addModule(new PoilAuModule());
|
||||
app.addModule(new FourasModule());
|
||||
app.addModule(new TodoModule());
|
||||
return app.exec();
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ bool SparrowModule::messageHandler(Message msg)
|
||||
}
|
||||
else if(msg.args.compare("!version") == 0)
|
||||
{
|
||||
answer = say("sparrowModule v1.0");
|
||||
answer = say("sparrowModule v1.1");
|
||||
return true;
|
||||
}
|
||||
else if(msg.args.compare("re", Qt::CaseInsensitive) == 0)
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "message.h"
|
||||
#include <time.h>
|
||||
#include <QStringList>
|
||||
#include <QDateTime>
|
||||
|
||||
TodoModule::TodoModule()
|
||||
{
|
||||
@ -18,26 +19,121 @@ bool TodoModule::messageHandler(Message msg)
|
||||
Task t;
|
||||
int deltaIndex = 1;
|
||||
t.isPrivate = !msg.target.contains(getChan());
|
||||
t.emitter = msg.nick;
|
||||
t.date = time(NULL);
|
||||
t.recipient = msg.nick;
|
||||
t.repeat = 0;
|
||||
QStringList splitter = msg.args.split(' ');
|
||||
if(splitter[deltaIndex].compare("to") == 0)
|
||||
{
|
||||
deltaIndex += 2;
|
||||
t.emitter = splitter[2];
|
||||
t.recipient = splitter[2];
|
||||
}
|
||||
if(splitter.size() < deltaIndex+2)
|
||||
return true;
|
||||
QString dateString = splitter[deltaIndex];
|
||||
QStringList dateSplitter;
|
||||
bool ok;
|
||||
if(dateString.startsWith("date("))
|
||||
{
|
||||
//t.date += dateString;
|
||||
answer = usage(DATE);
|
||||
dateString = dateString.mid(5, dateString.size() - 6);
|
||||
dateSplitter = dateString.split('/');
|
||||
if(dateSplitter.size() < 2)
|
||||
return true;
|
||||
int day = dateSplitter[0].toUInt(&ok);
|
||||
if(!ok || day > 31 || day < 1) return true;
|
||||
dateSplitter = dateSplitter[1].split('-');
|
||||
int month = dateSplitter[0].toUInt(&ok);
|
||||
if(!ok || month > 12 || month < 1) return true;
|
||||
int hours = 0;
|
||||
int minutes = 0;
|
||||
int seconds = 0;
|
||||
if(dateSplitter.size() > 1)
|
||||
{
|
||||
dateSplitter = dateSplitter[1].split(':');
|
||||
hours = dateSplitter[0].toUInt(&ok);
|
||||
if(!ok || hours > 23) return true;
|
||||
if(dateSplitter.size() > 1)
|
||||
{
|
||||
minutes = dateSplitter[1].toUInt(&ok);
|
||||
if(!ok || minutes > 59) return true;
|
||||
}
|
||||
if(dateSplitter.size() > 2)
|
||||
{
|
||||
seconds = dateSplitter[2].toUInt(&ok);
|
||||
if(!ok || seconds > 59) return true;
|
||||
}
|
||||
}
|
||||
QDateTime date(QDate(QDate::currentDate().year(), month, day), QTime(hours, minutes, seconds));
|
||||
t.date = date.toTime_t();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
answer = usage(DURATION);
|
||||
dateSplitter = dateString.split(':');
|
||||
int hours = dateSplitter[0].toUInt(&ok);
|
||||
int minutes = 0;
|
||||
int seconds = 0;
|
||||
if(!ok) return true;
|
||||
if(dateSplitter.size() > 1)
|
||||
{
|
||||
minutes = dateSplitter[1].toUInt(&ok);
|
||||
if(!ok || minutes > 59) return true;
|
||||
}
|
||||
if(dateSplitter.size() > 2)
|
||||
{
|
||||
seconds = dateSplitter[2].toUInt(&ok);
|
||||
if(!ok || seconds > 59) return true;
|
||||
}
|
||||
QDateTime date = QDateTime::currentDateTime();
|
||||
minutes += hours*60;
|
||||
seconds += minutes*60;
|
||||
date.addSecs(seconds);
|
||||
t.date = date.toTime_t();
|
||||
}
|
||||
|
||||
++deltaIndex;
|
||||
if(splitter[deltaIndex].compare("every") == 0)
|
||||
{
|
||||
answer = usage(DURATION);
|
||||
dateSplitter = dateString.split(':');
|
||||
int hours = dateSplitter[0].toUInt(&ok);
|
||||
int minutes = 0;
|
||||
int seconds = 0;
|
||||
if(!ok) return true;
|
||||
if(dateSplitter.size() > 1)
|
||||
{
|
||||
minutes = dateSplitter[1].toUInt(&ok);
|
||||
if(!ok || minutes > 59) return true;
|
||||
}
|
||||
if(dateSplitter.size() > 2)
|
||||
{
|
||||
seconds = dateSplitter[2].toUInt(&ok);
|
||||
if(!ok || seconds > 59) return true;
|
||||
}
|
||||
minutes += hours*60;
|
||||
seconds += minutes*60;
|
||||
t.repeat = seconds;
|
||||
deltaIndex += 2;
|
||||
}
|
||||
QString desc;
|
||||
bool first = true;
|
||||
for(int i=deltaIndex; i<splitter.size(); ++i)
|
||||
{
|
||||
if(first)
|
||||
first = false;
|
||||
else
|
||||
desc.append(" ");
|
||||
desc.append(splitter[i]);
|
||||
}
|
||||
t.description = desc;
|
||||
t.emitter = msg.nick;
|
||||
tasks.push_back(t);
|
||||
answer = say(QString("todo successfully added : from %1 to %2 triggering the %3, repeating every %4 seconds, and diplaying this message : %5")
|
||||
.arg(t.emitter)
|
||||
.arg(t.recipient)
|
||||
.arg(QDateTime::fromTime_t(t.date).toString())
|
||||
.arg((int)(t.repeat))
|
||||
.arg(t.description));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@ -47,26 +143,13 @@ QString TodoModule::usage(int type)
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
default:
|
||||
case TODO:
|
||||
return say("usage = !todo [to TARGET] DATE | DURATION [every DURATION] DESCRIPTION");
|
||||
case DURATION:
|
||||
return say("DURATION = HOURS[:MINUTES[:SECONDS]]");
|
||||
case DATE:
|
||||
return say("DATE = date(DAY/MONTH-[HOUR[:MINUTE[:SECOND]]])");
|
||||
return say("DATE = date(DAY/MONTH[-HOUR[:MINUTE[:SECOND]]])");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void TodoModule::addTask(unsigned long date, unsigned long repeat, QString description, QString emitter, QString recipient, bool isPrivate)
|
||||
{
|
||||
Task t;
|
||||
t.date = date;
|
||||
t.description = description;
|
||||
t.emitter = emitter;
|
||||
t.recipient = recipient;
|
||||
t.repeat = repeat;
|
||||
t.isPrivate = isPrivate;
|
||||
tasks.push_back(t);
|
||||
// TODO -> append it to save file
|
||||
}
|
||||
|
@ -27,8 +27,6 @@ public:
|
||||
|
||||
virtual bool messageHandler(Message msg);
|
||||
virtual QString getName() {return "todo";}
|
||||
|
||||
void addTask(unsigned long date, unsigned long repeat, QString description, QString emitter, QString recipient, bool isPrivate);
|
||||
};
|
||||
|
||||
#endif // TODOMODULE_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user