示例#1
0
void GreetModule::onMessageReceived(IrcMessage* message) {
	if (message->type() == IrcMessage::Join) {
			IrcJoinMessage* msg = static_cast<IrcJoinMessage*>(message);
			QString name = msg->sender().name();
			if (name != bot->nickName()) {
				QString greet = QString("Hi %1! Welcome in %2.").arg(name).arg(msg->channel());
				bot->sendCommand(IrcCommand::createMessage(msg->channel(), greet));
				out << "Greeted " << name << "." << endl;
			} else {
				QString enter = QString("enters %1 and fades to the background, immediatly available when somebody needs his services.").arg(msg->channel());
				bot->sendCommand(IrcCommand::createCtcpAction(msg->channel(), enter));
				out << "Joined " << msg->channel() << "." << endl;
			}
	} else if (message->type() == IrcMessage::Part) {
			IrcPartMessage* msg = static_cast<IrcPartMessage*>(message);
			QString name = msg->sender().name();
			QString bye = QString(" is shocked that %1 left %2 in favour of another channel.")
			.arg(name).arg(msg->channel());
			bot->sendCommand(IrcCommand::createCtcpAction(msg->channel(), bye));
			out << "Said good-bye to " << name << "." << endl;
			/*
	} else if (message->type() == IrcMessage::Quit) {
			IrcQuitMessage* msg = static_cast<IrcQuitMessage*>(message);
			QString name = msg->sender().name();
			QString bye = QString(" is a little sad that %1 left.").arg(name);
			bot->sendCommand(IrcCommand::createCtcpAction(bot->channel(), bye));
			out << "Said good-bye to " << name << "." << endl;
			*/
	}
}
示例#2
0
void MyIrcSession::on_parted(IrcMessage *message) {
	IrcPartMessage *m = (IrcPartMessage *) message;
	bool flags = 0;
	std::string nickname = TO_UTF8(m->sender().name());
	flags = correctNickname(nickname);
	LOG4CXX_INFO(logger, user << ": " << nickname << " parted " << TO_UTF8(m->channel()) + suffix);
	np->handleParticipantChanged(user, nickname, TO_UTF8(m->channel()) + suffix,(int) flags, pbnetwork::STATUS_NONE, TO_UTF8(m->reason()));
}
示例#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
    */
}
示例#4
0
void tst_IrcMessage::testPartMessage()
{
    QFETCH(bool, valid);
    QFETCH(QByteArray, data);
    QFETCH(QString, channel);
    QFETCH(QString, reason);

    IrcConnection connection;
    IrcMessage* message = IrcMessage::fromData(data, &connection);
    QCOMPARE(message->type(), IrcMessage::Part);
    QCOMPARE(message->command(), QString("PART"));
    QCOMPARE(message->property("valid").toBool(), valid);
    QCOMPARE(message->property("channel").toString(), channel);
    QCOMPARE(message->property("reason").toString(), reason);

    IrcPartMessage* partMessage = qobject_cast<IrcPartMessage*>(message);
    QVERIFY(partMessage);
    QCOMPARE(partMessage->isValid(), valid);
    QCOMPARE(partMessage->channel(), channel);
    QCOMPARE(partMessage->reason(), reason);
}