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