the bot now recognises ops
This commit is contained in:
parent
1644739ff7
commit
b86a0c1845
@ -5,13 +5,13 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
Message::Message(QString str)
|
||||
Message::Message(QString str, UserList users)
|
||||
{
|
||||
if(str.startsWith("PING"))
|
||||
{
|
||||
command = "PING";
|
||||
target = "PING";
|
||||
src = str.right(str.size()-(str.indexOf(':')+1));
|
||||
src = NULL;
|
||||
args = str;
|
||||
}
|
||||
else
|
||||
@ -25,7 +25,8 @@ Message::Message(QString str)
|
||||
// the interesting infos before the separator are separated by spaces
|
||||
QStringList list = str.split(' ');
|
||||
// source of the message
|
||||
src = list.takeFirst();
|
||||
QString nick = list.takeFirst();
|
||||
src = users.getFromNick(nick.left(nick.indexOf('!')));
|
||||
// command issued by the source
|
||||
command = list.takeFirst();
|
||||
// target of the command
|
||||
|
@ -3,15 +3,17 @@
|
||||
|
||||
#include <string>
|
||||
#include <QString>
|
||||
#include <vector>
|
||||
#include "user.h"
|
||||
|
||||
class Message
|
||||
{
|
||||
public:
|
||||
QString src;
|
||||
User* src;
|
||||
QString command;
|
||||
QString target;
|
||||
QString args;
|
||||
Message(QString str);
|
||||
Message(QString str, UserList users);
|
||||
~Message();
|
||||
};
|
||||
|
||||
|
@ -24,7 +24,7 @@ void SparrowBot::receiveMsg(QString msg)
|
||||
sendRawMessage("JOIN #" + chan + "\r\n");
|
||||
break;
|
||||
case ON_CHAN :
|
||||
handleMessage(Message(msg));
|
||||
handleMessage(Message(msg, users));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -40,18 +40,18 @@ void SparrowBot::forceStatus(int newStatus)
|
||||
else
|
||||
{
|
||||
status = OFFLINE;
|
||||
users.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void SparrowBot::handleMessage(Message msg)
|
||||
{
|
||||
//char* str = msg.args.toStdString().c_str();
|
||||
if(msg.command.compare(QString("PRIVMSG"), Qt::CaseInsensitive) == 0)
|
||||
{
|
||||
// message
|
||||
|
||||
|
||||
if(msg.args.compare("!update") == 0)
|
||||
if(msg.args.compare("!update") == 0 && msg.src != NULL && msg.src->isOp())
|
||||
{
|
||||
sendRawMessage("QUIT :i'll be back\r\n");
|
||||
exit(0);
|
||||
@ -59,8 +59,13 @@ void SparrowBot::handleMessage(Message msg)
|
||||
if(msg.args.compare("!list") == 0)
|
||||
{
|
||||
string str = "Online users : ";
|
||||
for(User u : users)
|
||||
str += u.getNick().toStdString() + " ";
|
||||
for(User* u : users)
|
||||
str += u->getNick().toStdString() + " ";
|
||||
say(str);
|
||||
str = "Online ops : ";
|
||||
for(User* u : users)
|
||||
if(u->isOp())
|
||||
str += u->getNick().toStdString() + " ";
|
||||
say(str);
|
||||
}
|
||||
}
|
||||
@ -71,9 +76,9 @@ void SparrowBot::handleMessage(Message msg)
|
||||
QStringList names = msg.args.split(' ');
|
||||
for(QString s : names)
|
||||
{
|
||||
User u = User(s);
|
||||
User* u = new User(s);
|
||||
users.push_back(u);
|
||||
sendRawMessage("WHOIS "+u.getNick().toStdString()+"\r\n");
|
||||
sendRawMessage("WHOIS "+u->getNick().toStdString()+"\r\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,6 @@
|
||||
#include "user.h"
|
||||
#include "message.h"
|
||||
#include <QObject>
|
||||
#include <vector>
|
||||
|
||||
class SparrowBot : public QObject
|
||||
{
|
||||
@ -16,7 +15,7 @@ class SparrowBot : public QObject
|
||||
std::string chan;
|
||||
int status;
|
||||
|
||||
std::vector<User> users;
|
||||
UserList users;
|
||||
public:
|
||||
SparrowBot() : nick("SparrowBot"), chan("epicsparrow"), status(OFFLINE) {}
|
||||
SparrowBot(std::string nick_, std::string chan_) : nick(nick_), chan(chan_), status(OFFLINE) {}
|
||||
|
16
user.cpp
16
user.cpp
@ -2,8 +2,8 @@
|
||||
|
||||
User::User(QString str)
|
||||
{
|
||||
isOp = (str.at(0) == '@');
|
||||
if(isOp)
|
||||
op = (str.at(0) == '@');
|
||||
if(op)
|
||||
str = str.remove(0, 1);
|
||||
nick = str;
|
||||
}
|
||||
@ -13,3 +13,15 @@ QString User::getNick()
|
||||
return nick;
|
||||
}
|
||||
|
||||
bool User::isOp()
|
||||
{
|
||||
return op;
|
||||
}
|
||||
|
||||
User* UserList::getFromNick(QString nick)
|
||||
{
|
||||
for(User* u : *this)
|
||||
if(nick.compare(u->getNick()) == 0)
|
||||
return u;
|
||||
return NULL;
|
||||
}
|
||||
|
10
user.h
10
user.h
@ -2,15 +2,23 @@
|
||||
#define USER_H
|
||||
|
||||
#include <QString>
|
||||
#include <vector>
|
||||
|
||||
class User
|
||||
{
|
||||
QString nick;
|
||||
bool isOp;
|
||||
bool op;
|
||||
|
||||
public:
|
||||
User(QString str);
|
||||
QString getNick();
|
||||
bool isOp();
|
||||
};
|
||||
|
||||
class UserList : public std::vector<User*>
|
||||
{
|
||||
public:
|
||||
User* getFromNick(QString nick);
|
||||
};
|
||||
|
||||
#endif // USER_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user