Beispiel #1
0
void MyIrcSession::on_messageReceived(IrcMessage *message) {
	IrcPrivateMessage *m = (IrcPrivateMessage *) message;
	if (m->isRequest()) {
		QString request = m->message().split(" ", QString::SkipEmptyParts).value(0).toUpper();
		if (request == "PING" || request == "TIME" || request == "VERSION") {
			LOG4CXX_INFO(logger, user << ": " << TO_UTF8(request) << " received and has been answered");
			return;
		}
	}

	QString msg = m->message();
	if (m->isAction()) {
		msg = QString("/me ") + msg;
	}

	std::string target = TO_UTF8(m->target());
	LOG4CXX_INFO(logger, user << ": Message from " << target);
	if (target.find("#") == 0) {
		std::string nickname = TO_UTF8(m->sender().name());
		correctNickname(nickname);
		np->handleMessage(user, target + suffix, TO_UTF8(msg), nickname);
	}
	else {
		std::string nickname = TO_UTF8(m->sender().name());
		correctNickname(nickname);
		LOG4CXX_INFO(logger, nickname + suffix);
		np->handleMessage(user, nickname + suffix, TO_UTF8(msg));
	}
}
Beispiel #2
0
void MyIrcSession::on_messageReceived(IrcMessage *message) {
	IrcPrivateMessage *m = (IrcPrivateMessage *) message;
	if (m->isRequest()) {
		QString request = m->message().split(" ", QString::SkipEmptyParts).value(0).toUpper();
		if (request == "PING" || request == "TIME" || request == "VERSION") {
			LOG4CXX_INFO(logger, user << ": " << TO_UTF8(request) << " received and has been answered");
			return;
		}
	}

	QString msg = m->message();
	if (m->isAction()) {
		msg = QString("/me ") + msg;
	}
	QString html = "";//msg;
	CommuniBackport::toPlainText(msg);

	// TODO: Communi produces invalid html now...
// 	if (html == msg) {
// 		html = "";
// 	}
// 	else {
// 		html = IrcUtil::messageToHtml(html);
// 	}

	std::string target = TO_UTF8(m->target().toLower());
	LOG4CXX_INFO(logger, user << ": Message from " << target);
	if (target.find("#") == 0) {
		std::string nickname = TO_UTF8(m->sender().name());
		correctNickname(nickname);
		np->handleMessage(user, target + suffix, TO_UTF8(msg), nickname, TO_UTF8(html));
	}
	else {
		std::string nickname = TO_UTF8(m->sender().name());
		correctNickname(nickname);
		if (m_pms.find(nickname) != m_pms.end()) {
			if (hasIRCBuddy(m_pms[nickname], nickname)) {
				LOG4CXX_INFO(logger, nickname);
				np->handleMessage(user, m_pms[nickname] + suffix, TO_UTF8(msg), nickname, TO_UTF8(html), "", false, true);
				return;
			}
			else {
				nickname = nickname + suffix;
			}
		}
		else {
			nickname = nickname + suffix;
		}

		LOG4CXX_INFO(logger, nickname);
		np->handleMessage(user, nickname, TO_UTF8(msg), "", TO_UTF8(html));
	}
}
Beispiel #3
0
void dlgIRC::onMessageReceived( IrcMessage* msg )
{
    switch( msg->type() )
    {
    case IrcMessage::Type::Join: {
        IrcJoinMessage *rmsg = static_cast<IrcJoinMessage*>(msg);
        slot_joined( rmsg->sender().name(), rmsg->channel() );
        break;
        }
    case IrcMessage::Type::Notice: {
        IrcNoticeMessage *rmsg = static_cast<IrcNoticeMessage*>(msg);
        irc_gotMsg( rmsg->sender().name(), rmsg->target(), rmsg->message() );
        break;
        }
    case IrcMessage::Type::Private: {
        IrcPrivateMessage *rmsg = static_cast<IrcPrivateMessage*>(msg);
        irc_gotMsg( rmsg->sender().name(), rmsg->target(), rmsg->message() );
        break;
        }
    case IrcMessage::Type::Numeric: {
        IrcNumericMessage *rmsg = static_cast<IrcNumericMessage*>(msg);
        irc_gotMsg3( rmsg->sender().name(), rmsg->code(), rmsg->parameters() );
        break;
        }
    case IrcMessage::Type::Part: {
        IrcPartMessage *rmsg = static_cast<IrcPartMessage*>(msg);
        slot_parted( rmsg->sender().name(), rmsg->channel(), rmsg->reason() );
        break;
        }
    case IrcMessage::Type::Unknown:
        irc_gotMsg2( msg->sender().name(), msg->parameters() );
        break;
    }
    /*
    Nick 	IrcNickMessage
    Quit 	IrcQuitMessage
    Topic 	IrcTopicMessage
    Invite 	IrcInviteMessage
    Kick 	IrcKickMessage
    Mode 	IrcModeMessage
    Ping 	IrcPingMessage
    Pong 	IrcPongMessage
    Error 	IrcErrorMessage
    */
}
Beispiel #4
0
void MyIrcSession::on_messageReceived(IrcMessage *message) {
	IrcPrivateMessage *m = (IrcPrivateMessage *) message;

	std::string target = TO_UTF8(m->target());
	LOG4CXX_INFO(logger, user << ": Message from " << target);
	if (target.find("#") == 0) {
		bool flags = 0;
		std::string nickname = TO_UTF8(m->sender().name());
		flags = correctNickname(nickname);
		np->handleMessage(user, target + suffix, TO_UTF8(m->message()), nickname);
	}
	else {
		bool flags = 0;
		std::string nickname = TO_UTF8(m->sender().name());
		flags = correctNickname(nickname);
		np->handleMessage(user, nickname, TO_UTF8(m->message()));
	}
}
void tst_IrcMessage::testPrivateMessage()
{
    QFETCH(bool, valid);
    QFETCH(QString, cap);
    QFETCH(QByteArray, data);
    QFETCH(QString, target);
    QFETCH(QString, content);
    QFETCH(bool, priv);
    QFETCH(bool, action);
    QFETCH(bool, request);
    QFETCH(uint, flags);

    IrcConnection connection;
    connection.setNickName("communi");
    TestProtocol protocol(cap, &connection);
    static_cast<FriendConnection*>(&connection)->setProtocol(&protocol);

    IrcMessage* message = IrcMessage::fromData(data, &connection);
    QCOMPARE(message->type(), IrcMessage::Private);
    QCOMPARE(message->command(), QString("PRIVMSG"));
    QCOMPARE(message->property("valid").toBool(), valid);
    QCOMPARE(message->property("target").toString(), target);
    QCOMPARE(message->property("content").toString(), content);
    QCOMPARE(message->property("private").toBool(), priv);
    QCOMPARE(message->property("action").toBool(), action);
    QCOMPARE(message->property("request").toBool(), request);
    QCOMPARE(message->property("flags").toUInt(), flags);

    IrcPrivateMessage* privateMessage = qobject_cast<IrcPrivateMessage*>(message);
    QVERIFY(privateMessage);
    QCOMPARE(privateMessage->isValid(), valid);
    QCOMPARE(privateMessage->target(), target);
    QCOMPARE(privateMessage->content(), content);
    QCOMPARE(privateMessage->isPrivate(), priv);
    QCOMPARE(privateMessage->isAction(), action);
    QCOMPARE(privateMessage->isRequest(), request);
    QCOMPARE(static_cast<uint>(privateMessage->flags()), flags);
}