From 98c8a64d6ab7c4d48b5a0876a37bdc6946e460ad Mon Sep 17 00:00:00 2001 From: Anselme Date: Thu, 21 May 2015 20:10:39 +0200 Subject: [PATCH] the bot now understands renaming, and answer to "plop ?" --- sparrowbot.cpp | 16 ++++++++++++---- user.cpp | 5 +++++ user.h | 1 + 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/sparrowbot.cpp b/sparrowbot.cpp index fad1474..d2a4332 100644 --- a/sparrowbot.cpp +++ b/sparrowbot.cpp @@ -46,16 +46,16 @@ void SparrowBot::forceStatus(int newStatus) void SparrowBot::handleMessage(Message msg) { + // si la ligne est un message if(msg.command.compare(QString("PRIVMSG"), Qt::CaseInsensitive) == 0) { - // message - - + // mise à jour du bot if(msg.args.compare("!update") == 0 && msg.src != NULL && msg.src->isOp()) { sendRawMessage("QUIT :i'll be back\r\n"); exit(0); } + // affiche les gens connectés if(msg.args.compare("!list") == 0) { string str = "Online users : "; @@ -68,9 +68,17 @@ void SparrowBot::handleMessage(Message msg) str += u->getNick().toStdString() + " "; say(str); } + if(msg.args.compare("plop ?") == 0) + action("est content"); } - if(msg.command.compare(QString("353"), Qt::CaseInsensitive) == 0) + // renommage + else if(msg.command.compare(QString("NICK"), Qt::CaseInsensitive) == 0) + msg.src->rename(msg.args); + + // 353 = code de la ligne qui liste les nicks connectés + // on les parse et on effectue un WHOIS sur chaque nick + else if(msg.command.compare(QString("353"), Qt::CaseInsensitive) == 0) { // names QStringList names = msg.args.split(' '); diff --git a/user.cpp b/user.cpp index a1bfa5f..a7df4d5 100644 --- a/user.cpp +++ b/user.cpp @@ -8,6 +8,11 @@ User::User(QString str) nick = str; } +void User::rename(QString newNick) +{ + nick = newNick; +} + QString User::getNick() { return nick; diff --git a/user.h b/user.h index f13e487..64ff102 100644 --- a/user.h +++ b/user.h @@ -11,6 +11,7 @@ class User public: User(QString str); + void rename(QString newNick); QString getNick(); bool isOp(); };