<commit_before>#include "providers/twitch/TwitchMessageBuilder.hpp"

#include "Application.hpp"
#include "controllers/accounts/AccountController.hpp"
#include "controllers/highlights/HighlightController.hpp"
#include "controllers/ignores/IgnoreController.hpp"
#include "controllers/pings/PingController.hpp"
#include "debug/Log.hpp"
#include "messages/Message.hpp"
#include "providers/chatterino/ChatterinoBadges.hpp"
#include "providers/twitch/TwitchBadges.hpp"
#include "providers/twitch/TwitchChannel.hpp"
#include "providers/twitch/TwitchServer.hpp"
#include "singletons/Emotes.hpp"
#include "singletons/Resources.hpp"
#include "singletons/Settings.hpp"
#include "singletons/Theme.hpp"
#include "singletons/WindowManager.hpp"
#include "util/IrcHelpers.hpp"
#include "widgets/Window.hpp"

#include <QApplication>
#include <QDebug>
#include <QMediaPlayer>
#include <QStringRef>
#include <QColor>
#include <boost/variant.hpp>

namespace {

QColor getRandomColor(QVariant value)
{
    static const std::vector<QColor> twitchUsernameColors = {
        QColor(255, 0, 0), // Red
        QColor(0, 0, 255), // Blue
        QColor(0, 255, 0), // Green
        QColor(178, 34, 34), // FireBrick
        QColor(255, 127, 80), // Coral
        QColor(154, 205, 50), // YellowGreen
        QColor(255, 69, 0), // OrangeRed
        QColor(46, 139, 87), // SeaGreen
        QColor(218, 165, 32), // GoldenRod
        QColor(210, 105, 30), // Chocolate
        QColor(95, 158, 160), // CadetBlue
        QColor(30, 144, 255), // DodgerBlue
        QColor(255, 105, 180), // HotPink
        QColor(138, 43, 226), // BlueViolet
        QColor(0, 255, 127) // SpringGreen
    };

    // If someday Twitch will replace all the user-ids with strings
    // then we just choose a random color.
    const auto userId = value.toInt();
    const auto index = (userId ? userId : std::rand())
        % twitchUsernameColors.size();
    return twitchUsernameColors[index];
}

}

namespace chatterino {

TwitchMessageBuilder::TwitchMessageBuilder(
    Channel *_channel, const Communi::IrcPrivateMessage *_ircMessage,
    const MessageParseArgs &_args)
    : channel(_channel)
    , twitchChannel(dynamic_cast<TwitchChannel *>(_channel))
    , ircMessage(_ircMessage)<commit_msg>try to improve readability of the "grayname colorize" function<commit_after>#include "providers/twitch/TwitchMessageBuilder.hpp"

#include "Application.hpp"
#include "controllers/accounts/AccountController.hpp"
#include "controllers/highlights/HighlightController.hpp"
#include "controllers/ignores/IgnoreController.hpp"
#include "controllers/pings/PingController.hpp"
#include "debug/Log.hpp"
#include "messages/Message.hpp"
#include "providers/chatterino/ChatterinoBadges.hpp"
#include "providers/twitch/TwitchBadges.hpp"
#include "providers/twitch/TwitchChannel.hpp"
#include "providers/twitch/TwitchServer.hpp"
#include "singletons/Emotes.hpp"
#include "singletons/Resources.hpp"
#include "singletons/Settings.hpp"
#include "singletons/Theme.hpp"
#include "singletons/WindowManager.hpp"
#include "util/IrcHelpers.hpp"
#include "widgets/Window.hpp"

#include <QApplication>
#include <QColor>
#include <QDebug>
#include <QMediaPlayer>
#include <QStringRef>
#include <boost/variant.hpp>

namespace {

QColor getRandomColor(const QVariant &userId)
{
    static const std::vector<QColor> twitchUsernameColors = {
        {255, 0, 0},      // Red
        {0, 0, 255},      // Blue
        {0, 255, 0},      // Green
        {178, 34, 34},    // FireBrick
        {255, 127, 80},   // Coral
        {154, 205, 50},   // YellowGreen
        {255, 69, 0},     // OrangeRed
        {46, 139, 87},    // SeaGreen
        {218, 165, 32},   // GoldenRod
        {210, 105, 30},   // Chocolate
        {95, 158, 160},   // CadetBlue
        {30, 144, 255},   // DodgerBlue
        {255, 105, 180},  // HotPink
        {138, 43, 226},   // BlueViolet
        {0, 255, 127},    // SpringGreen
    };

    bool ok = true;
    int colorSeed = userId.toInt(&ok);
    if (!ok)
    {
        // We were unable to convert the user ID to an integer, this means Twitch has decided to start using non-integer user IDs
        // Just randomize the users color
        colorSeed = std::rand();
    }

    const auto colorIndex = colorSeed % twitchUsernameColors.size();
    return twitchUsernameColors[colorIndex];
}

}  // namespace

namespace chatterino {

TwitchMessageBuilder::TwitchMessageBuilder(
    Channel *_channel, const Communi::IrcPrivateMessage *_ircMessage,
    const MessageParseArgs &_args)
    : channel(_channel)
    , twitchChannel(dynamic_cast<TwitchChannel *>(_channel))
    , ircMessage(_ircMessage)
{'fraction_non_alphanumeric': 0.1306122448979592, 'fraction_numerical': 0.04597207303974221, 'mean_word_length': 3.529182879377432, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6262564', 'n_tokens_mistral': 1695, 'n_tokens_neox': 1488, 'n_words': 349}