Ejemplo n.º 1
0
void CBDS::onChat(const QString &message)
{
    Viewer *v = qobject_cast<Viewer *>(sender());
    if (v)
    {
        if (message == "/debug")
        {
            v->setDebugReadable(!v->getDebugReadable());
            m_chat.addLine(new ChatLine(v->getDebugReadable() ? "Debug mode enabled. Type /debug again to disable." : "Debug mode disabled.", Q_NULLPTR, "#000000", "#FFFFFF", 0, v->getName()));
            return;
        }
        QScriptValue e = createViewerValue(v);
        e.setProperty("c", v->getTextcolor());
        e.setProperty("m", message);
        e.setProperty("f", v->getFont());
        if (m_cbo->callMessageFunction(e) && !e.property("X-Spam").toBool())
        {
            //There is an example for changing the background in the API docs. I'd prefer proper documentation.
            QString background = "#FFFFFF";
            if (e.property("background").isValid())
            {
                background = e.property("background").toString().toUpper();
                if (!QRegExp("#([0-9A-F|]{3}|[0-9A-F]{6})").exactMatch(background))
                {
                    emit m_cbo->warning("CSS message background hacks aren't supported since there is no browser support guarantee. If you feel i should add support let me know. IMHO CB should make stuff like this a viable option here and for notices and ensure browser support.");
                    background = "#FFFFFF";
                }
            }
            m_chat.addLine(new ChatLine(e.property("m").toString(), v, e.property("c").toString(), background));
        }
    }
}