Exemplo n.º 1
0
void QYoutubeChatEx::message(const QString message, const QString authorName, const QString authorImageLogo, bool isChatModerator, bool isChatOwner, bool isChatSponsor)
{
    bool blackListUser = blackList().contains( authorName );
    bool supportersListUser = supportersList().contains( authorName );

    QString userType = "";

    if (blackListUser)
        userType = "ignore";
    else
    if (supportersListUser||isChatSponsor)
        userType = "supporter";

    emit newMessage( ChatMessage( YOUTUBE_SERVICE, authorName, message , userType, this ) );
}
Exemplo n.º 2
0
void QTwitchChat::parseMessage()
{
    if( !socket_ )
        return;

    if( socket_->state() == QAbstractSocket::ConnectedState )
    {
        QString line = socket_->readLine();

        //qDebug() << line;

        //поадекватнее надо быть

        if( line.contains ( "376 " + DEFAULT_USER_NICK_NAME ) )
        {
            socket_->write( QString( "JOIN #" + channelName_ + "\r\n" ).toStdString().c_str() );
            getSelf();

            //emit newMessage( new QChatMessage( "qrc:/resources/twitchlogo.png", TWITCH_USER, "Connecting to " + channelName_ + "...", this ) );
            if( isShowSystemMessages() )
                emit newMessage( new QChatMessage( TWITCH_SERVICE, TWITCH_USER, "Connected to " + channelName_ + "...", "", this ) );

            getStatistic();
            if( statisticTimerId_ )
                statisticTimerId_ = startTimer( statisticInterval_ );
        }
        else if( line.contains( "PING" ) )
        {
            qDebug() << line;
            //socket_->write( "PONG tmi.twitch.tv\r\n" );
            socket_->write( "PONG :tmi.twitch.tv\r\n" );
        }
        else
        {
            //TODO: parse message
            if( line.contains( "PRIVMSG" ) && !line.contains( "HISTORYEND" ) && !line.contains( "USERCOLOR") )
            {
                QString nickName = line.mid( 1, line.indexOf( '!' ) - 1 );
                QString message = line.right( line.size() - line.indexOf( ':', 1 ) - 1 );

                //\r\n
                message = message.left( message.size() - 2 );

                //qDebug() << message;

                message = QChatMessage::replaceEscapeCharecters( message );
                message = insertEmotIcons( message );
                //message = QChatMessage::insertLinks( message );

                bool blackListUser = blackList().contains( nickName );
                bool supportersListUser = supportersList().contains( nickName );

                if( !isRemoveBlackListUsers() || !blackListUser )
                {
                    if( blackListUser )
                    {
                        emit newMessage( new QChatMessage( TWITCH_SERVICE, nickName, message, "ignore", this ) );
                    }
                    else
                    {
                        if( supportersListUser )
                        {
                            emit newMessage( new QChatMessage( TWITCH_SERVICE, nickName, message, "supporter", this ) );
                        }
                        else
                        {
                            if( isContainsAliases( message ) )
                            {
                                emit newMessage( new QChatMessage( TWITCH_SERVICE, nickName, message, "alias", this ) );
                            }
                            else
                            {
                                emit newMessage( new QChatMessage( TWITCH_SERVICE, nickName, message, "", this ) );
                            }
                        }
                    }
                }
            }
        }

        if( socket_->canReadLine() )
        {
            parseMessage();
        }
    }
}
Exemplo n.º 3
0
void QYoutubeChat::onMessagesLoaded()
{
    QNetworkReply * reply = qobject_cast< QNetworkReply * >( sender() );

    const QString HTML_CONTENT_START = "<html_content><![CDATA[";
    const QString HTML_CONTENT_END = "]]></html_content>";

    QString messagesData = reply->readAll();

    int startMessagesDataPos = messagesData.indexOf( HTML_CONTENT_START ) + HTML_CONTENT_START.length();
    int endMessagesDataPos = messagesData.indexOf( HTML_CONTENT_END, startMessagesDataPos ) - 1;

    messagesData = messagesData.mid( startMessagesDataPos, endMessagesDataPos - startMessagesDataPos + 1 );

    QJsonParseError parseError;

    QJsonDocument jsonDoc = QJsonDocument::fromJson( QByteArray( messagesData.toStdString().c_str() ), &parseError );

    if( parseError.error == QJsonParseError::NoError )
    {
        if( jsonDoc.isObject() )
        {
            QJsonObject jsonObj = jsonDoc.object();

            QJsonArray jsonMessagesArr = jsonObj[ "comments" ].toArray();

            QList< QJsonObject > messagesList;

            foreach( const QJsonValue & value, jsonMessagesArr )
            {
                messagesList.append( value.toObject() );
            }

            qSort( messagesList.begin(), messagesList.end(), cmpJsonObjectByTimeCreated );

            for( int i = 0; i < messagesList.size(); ++i )
            {
                QJsonObject jsonMessageInfo = messagesList[ i ];

                QString message = jsonMessageInfo[ "comment" ].toString();
                QString nickName = jsonMessageInfo[ "author_name" ].toString();

                bool blackListUser = blackList().contains( nickName );
                bool supportersListUser = supportersList().contains( nickName );

                if( !isRemoveBlackListUsers() || !blackListUser )
                {
                    if( blackListUser )
                    {
                        //TODO: игнорируемые
                        emit newMessage( new QChatMessage( YOUTUBE_SERVICE, nickName, message, "ignore", this ) );
                    }
                    else
                    {
                        if( supportersListUser )
                        {
                            //TODO: саппортеры
                            emit newMessage( new QChatMessage( YOUTUBE_SERVICE, nickName, message, "supporter", this ) );
                        }
                        else
                        {
                            if( isContainsAliases( message ) )
                            {
                                //TODO: сообщение к стримеру
                                emit newMessage( new QChatMessage( YOUTUBE_SERVICE, nickName, message, "alias", this ) );
                            }
                            else
                            {
                                //TODO: простое сообщение
                                emit newMessage( new QChatMessage( YOUTUBE_SERVICE, nickName, message, "", this ) );
                            }
                        }
                    }
                }
            }

            lastMessageTime_ = QString::number( jsonObj[ "latest_time" ].toInt() );
        }