diff --git a/CHANGELOG.md b/CHANGELOG.md index d1d19d391..3fd6af721 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unversioned +- Minor: Made `Try to find usernames without @ prefix` option still resolve usernames when special characters (commas, dots, (semi)colons, exclamation mark, question mark) are appended to them. (#2212) - Minor: Made usercard update user's display name (#2160) - Minor: Added placeholder text for message text input box. (#2143, #2149) - Minor: Added support for FrankerFaceZ badges. (#2101, part of #1658) diff --git a/src/providers/twitch/TwitchMessageBuilder.cpp b/src/providers/twitch/TwitchMessageBuilder.cpp index ec93e8bc3..c7c7db98f 100644 --- a/src/providers/twitch/TwitchMessageBuilder.cpp +++ b/src/providers/twitch/TwitchMessageBuilder.cpp @@ -29,8 +29,13 @@ namespace { +const QString regexHelpString("(\\w+)[.,!?;:]*?$"); + // matches a mention with punctuation at the end, like "@username," or "@username!!!" where capture group would return "username" -const QRegularExpression mentionRegex("^@(\\w+)[.,!?;]*?$"); +const QRegularExpression mentionRegex("^@" + regexHelpString); + +// if findAllUsernames setting is enabled, matches strings like in the examples above, but without @ symbol at the beginning +const QRegularExpression allUsernamesMentionRegex("^" + regexHelpString); const QSet zeroWidthEmotes{ "SoSnowy", "IceCold", "SantaHat", "TopHat", @@ -474,6 +479,7 @@ void TwitchMessageBuilder::addTextOrEmoji(const QString &string_) if (match.hasMatch()) { QString username = match.captured(1); + this->emplace(string, MessageElementFlag::BoldUsername, textColor, FontStyle::ChatMediumBold) ->setLink({Link::UserInfo, username}); @@ -488,15 +494,18 @@ void TwitchMessageBuilder::addTextOrEmoji(const QString &string_) if (this->twitchChannel != nullptr && getSettings()->findAllUsernames) { auto chatters = this->twitchChannel->accessChatters(); - if (chatters->contains(string)) + auto match = allUsernamesMentionRegex.match(string); + QString username = match.captured(1); + + if (match.hasMatch() && chatters->contains(username)) { this->emplace(string, MessageElementFlag::BoldUsername, textColor, FontStyle::ChatMediumBold) - ->setLink({Link::UserInfo, string}); + ->setLink({Link::UserInfo, username}); this->emplace( string, MessageElementFlag::NonBoldUsername, textColor) - ->setLink({Link::UserInfo, string}); + ->setLink({Link::UserInfo, username}); return; } }