diff --git a/src/providers/twitch/TwitchMessageBuilder.cpp b/src/providers/twitch/TwitchMessageBuilder.cpp index e5fa25005..934276f63 100644 --- a/src/providers/twitch/TwitchMessageBuilder.cpp +++ b/src/providers/twitch/TwitchMessageBuilder.cpp @@ -23,8 +23,41 @@ #include #include #include +#include #include +namespace { + +QColor getRandomColor(QVariant value) +{ + static const std::vector 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( @@ -466,10 +499,15 @@ void TwitchMessageBuilder::appendChannelName() void TwitchMessageBuilder::parseUsername() { - auto iterator = this->tags.find("color"); - if (iterator != this->tags.end()) + const auto iterator = this->tags.find("color"); + if (const auto color = iterator.value().toString(); !color.isEmpty()) { - this->usernameColor_ = QColor(iterator.value().toString()); + this->usernameColor_ = QColor(color); + } + else if (getSettings()->colorizeNicknames && + this->tags.contains("user-id")) + { + this->usernameColor_ = getRandomColor(this->tags.value("user-id")); } // username diff --git a/src/singletons/Settings.hpp b/src/singletons/Settings.hpp index a9c1fdb18..7dae93278 100644 --- a/src/singletons/Settings.hpp +++ b/src/singletons/Settings.hpp @@ -42,6 +42,8 @@ public: BoolSetting hideModerated = {"/appearance/messages/hideModerated", false}; BoolSetting hideModerationActions = { "/appearance/messages/hideModerationActions", false}; + BoolSetting colorizeNicknames = { + "/appearance/messages/colorizeNicknames", false}; // BoolSetting collapseLongMessages = // {"/appearance/messages/collapseLongMessages", false}; diff --git a/src/widgets/settingspages/GeneralPage.cpp b/src/widgets/settingspages/GeneralPage.cpp index 8b2fbfbd8..7b5f5e48a 100644 --- a/src/widgets/settingspages/GeneralPage.cpp +++ b/src/widgets/settingspages/GeneralPage.cpp @@ -217,6 +217,7 @@ void GeneralPage::initLayout(SettingsLayout &layout) // layout.addDropdown("Last read message style", {"Default"}); layout.addCheckbox("Hide moderated messages", s.hideModerated); layout.addCheckbox("Hide moderation messages", s.hideModerationActions); + layout.addCheckbox("Colorize gray nicknames", s.colorizeNicknames); layout.addDropdown( "Timeout stacking style", {"Stack", "Stack sparingly"}, s.timeoutStackStyle, [](int index) { return index; },