From 12fa816564d5088a72574b698812e68140ddccf2 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Wed, 6 Nov 2024 00:09:03 +0100 Subject: [PATCH 1/5] improve automod blocked term messaging --- src/providers/twitch/TwitchIrcServer.cpp | 51 +++++++++++++++++-- .../twitch/pubsubmessages/AutoMod.cpp | 24 +++++++++ .../twitch/pubsubmessages/AutoMod.hpp | 3 ++ src/singletons/Settings.hpp | 4 ++ src/widgets/settingspages/GeneralPage.cpp | 5 ++ 5 files changed, 84 insertions(+), 3 deletions(-) diff --git a/src/providers/twitch/TwitchIrcServer.cpp b/src/providers/twitch/TwitchIrcServer.cpp index 901ac0525..502900187 100644 --- a/src/providers/twitch/TwitchIrcServer.cpp +++ b/src/providers/twitch/TwitchIrcServer.cpp @@ -4,6 +4,7 @@ #include "common/Channel.hpp" #include "common/Common.hpp" #include "common/Env.hpp" +#include "common/Literals.hpp" #include "common/QLogging.hpp" #include "controllers/accounts/AccountController.hpp" #include "messages/LimitedQueueSnapshot.hpp" @@ -32,6 +33,7 @@ #include #include #include +#include #include #include @@ -488,9 +490,52 @@ void TwitchIrcServer::initialize() if (msg.status == "PENDING") { AutomodAction action(msg.data, channelID); - action.reason = QString("%1 level %2") - .arg(msg.contentCategory) - .arg(msg.contentLevel); + if (msg.reason == + PubSubAutoModQueueMessage::Reason::BlockedTerm) + { + auto numBlockedTermsMatched = + msg.blockedTermsFound.count(); + auto hideBlockedTerms = + getSettings() + ->streamerModeHideBlockedTermText && + getApp()->getStreamerMode()->isEnabled(); + if (!msg.blockedTermsFound.isEmpty()) + { + if (hideBlockedTerms) + { + action.reason = + u"matched " % + QString::number( + numBlockedTermsMatched) % + u" blocked term" % + (numBlockedTermsMatched > 1 ? u"s" + : u""); + } + else + { + action.reason = + u"matched " % + QString::number( + numBlockedTermsMatched) % + u" blocked term" % + (numBlockedTermsMatched > 1 ? u"s" + : u"") % + u": \"" % + msg.blockedTermsFound.join(u"\", \"") % + u"\""; + } + } + else + { + action.reason = "blocked term usage"; + } + } + else + { + action.reason = QString("%1 level %2") + .arg(msg.contentCategory) + .arg(msg.contentLevel); + } action.msgID = msg.messageID; action.message = msg.messageText; diff --git a/src/providers/twitch/pubsubmessages/AutoMod.cpp b/src/providers/twitch/pubsubmessages/AutoMod.cpp index 3dd3d77df..aaf2fe87e 100644 --- a/src/providers/twitch/pubsubmessages/AutoMod.cpp +++ b/src/providers/twitch/pubsubmessages/AutoMod.cpp @@ -2,6 +2,8 @@ #include "util/QMagicEnum.hpp" +#include + namespace chatterino { PubSubAutoModQueueMessage::PubSubAutoModQueueMessage(const QJsonObject &root) @@ -9,6 +11,7 @@ PubSubAutoModQueueMessage::PubSubAutoModQueueMessage(const QJsonObject &root) , data(root.value("data").toObject()) , status(this->data.value("status").toString()) { + qInfo() << "XXX: automod message over pubsub:" << root; auto oType = qmagicenum::enumCast(this->typeString); if (oType.has_value()) { @@ -41,6 +44,27 @@ PubSubAutoModQueueMessage::PubSubAutoModQueueMessage(const QJsonObject &root) messageSender.value("display_name").toString(); this->senderUserChatColor = QColor(messageSender.value("chat_color").toString()); + + if (this->reason == Reason::BlockedTerm) + { + // Attempt to read the blocked term(s) that caused this message to be blocked + const auto caughtMessageReason = + data.value("caught_message_reason").toObject(); + const auto blockedTermFailure = + caughtMessageReason.value("blocked_term_failure").toObject(); + const auto termsFound = + blockedTermFailure.value("terms_found").toArray(); + + for (const auto &termValue : termsFound) + { + const auto term = termValue.toObject(); + const auto termText = term.value("text").toString(); + if (!termText.isEmpty()) + { + this->blockedTermsFound.push_back(termText); + } + } + } } } // namespace chatterino diff --git a/src/providers/twitch/pubsubmessages/AutoMod.hpp b/src/providers/twitch/pubsubmessages/AutoMod.hpp index 3179abae3..a6147e7b2 100644 --- a/src/providers/twitch/pubsubmessages/AutoMod.hpp +++ b/src/providers/twitch/pubsubmessages/AutoMod.hpp @@ -4,6 +4,7 @@ #include #include #include +#include namespace chatterino { @@ -40,6 +41,8 @@ struct PubSubAutoModQueueMessage { QString senderUserDisplayName; QColor senderUserChatColor; + QStringList blockedTermsFound; + PubSubAutoModQueueMessage() = default; explicit PubSubAutoModQueueMessage(const QJsonObject &root); }; diff --git a/src/singletons/Settings.hpp b/src/singletons/Settings.hpp index fa039184e..4e664f396 100644 --- a/src/singletons/Settings.hpp +++ b/src/singletons/Settings.hpp @@ -337,6 +337,10 @@ public: "/streamerMode/supressLiveNotifications", false}; BoolSetting streamerModeSuppressInlineWhispers = { "/streamerMode/suppressInlineWhispers", true}; + BoolSetting streamerModeHideBlockedTermText = { + "/streamerMode/hideBlockedTermText", + true, + }; /// Ignored Phrases QStringSetting ignoredPhraseReplace = {"/ignore/ignoredPhraseReplace", diff --git a/src/widgets/settingspages/GeneralPage.cpp b/src/widgets/settingspages/GeneralPage.cpp index 58cc37319..03d80b6d9 100644 --- a/src/widgets/settingspages/GeneralPage.cpp +++ b/src/widgets/settingspages/GeneralPage.cpp @@ -667,6 +667,11 @@ void GeneralPage::initLayout(GeneralPageView &layout) layout.addCheckbox( "Hide moderation actions", s.streamerModeHideModActions, false, "Hide bans, timeouts, and automod messages from appearing in chat."); + layout.addCheckbox( + "Hide blocked terms", s.streamerModeHideBlockedTermText, false, + "Hide blocked terms from showing up in places like AutoMod messages. " + "This can be useful in case you have some blocked terms that you don't " + "want to show on stream."); layout.addCheckbox("Mute mention sounds", s.streamerModeMuteMentions, false, "Mute your ping sound from playing."); layout.addCheckbox( From 1199f5e7637d35548cc605f9b07ac127ad07e798 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Wed, 6 Nov 2024 17:14:32 +0100 Subject: [PATCH 2/5] clean up reason generation --- src/providers/twitch/TwitchIrcServer.cpp | 28 +++++++++++------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/providers/twitch/TwitchIrcServer.cpp b/src/providers/twitch/TwitchIrcServer.cpp index 502900187..7a662671d 100644 --- a/src/providers/twitch/TwitchIrcServer.cpp +++ b/src/providers/twitch/TwitchIrcServer.cpp @@ -149,6 +149,8 @@ bool shouldSendHelixChat() namespace chatterino { +using namespace literals; + TwitchIrcServer::TwitchIrcServer() : whispersChannel(new Channel("/whispers", Channel::Type::TwitchWhispers)) , mentionsChannel(new Channel("/mentions", Channel::Type::TwitchMentions)) @@ -504,25 +506,21 @@ void TwitchIrcServer::initialize() if (hideBlockedTerms) { action.reason = - u"matched " % - QString::number( - numBlockedTermsMatched) % - u" blocked term" % - (numBlockedTermsMatched > 1 ? u"s" - : u""); + u"matches %1 blocked term%2"_s.arg( + numBlockedTermsMatched, + numBlockedTermsMatched > 1 ? 's' + : ""); } else { action.reason = - u"matched " % - QString::number( - numBlockedTermsMatched) % - u" blocked term" % - (numBlockedTermsMatched > 1 ? u"s" - : u"") % - u": \"" % - msg.blockedTermsFound.join(u"\", \"") % - u"\""; + u"matches %1 blocked term%2 \"%3\""_s + .arg(numBlockedTermsMatched, + numBlockedTermsMatched > 1 + ? 's' + : "", + msg.blockedTermsFound.join( + u"\", \"")); } } else From 40490a90fbd91b887aa44461b80ad50cbbdcb56f Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Wed, 6 Nov 2024 17:16:12 +0100 Subject: [PATCH 3/5] remove unused include --- src/providers/twitch/TwitchIrcServer.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/providers/twitch/TwitchIrcServer.cpp b/src/providers/twitch/TwitchIrcServer.cpp index 7a662671d..a94ea7a4a 100644 --- a/src/providers/twitch/TwitchIrcServer.cpp +++ b/src/providers/twitch/TwitchIrcServer.cpp @@ -33,7 +33,6 @@ #include #include #include -#include #include #include From 8a69861ead13faab6a5c7a3f6ae0b580a6e432ad Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Wed, 6 Nov 2024 17:36:38 +0100 Subject: [PATCH 4/5] opsie --- src/providers/twitch/TwitchIrcServer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/providers/twitch/TwitchIrcServer.cpp b/src/providers/twitch/TwitchIrcServer.cpp index a94ea7a4a..e61cdb1db 100644 --- a/src/providers/twitch/TwitchIrcServer.cpp +++ b/src/providers/twitch/TwitchIrcServer.cpp @@ -507,7 +507,7 @@ void TwitchIrcServer::initialize() action.reason = u"matches %1 blocked term%2"_s.arg( numBlockedTermsMatched, - numBlockedTermsMatched > 1 ? 's' + numBlockedTermsMatched > 1 ? u"s" : ""); } else @@ -516,7 +516,7 @@ void TwitchIrcServer::initialize() u"matches %1 blocked term%2 \"%3\""_s .arg(numBlockedTermsMatched, numBlockedTermsMatched > 1 - ? 's' + ? u"s" : "", msg.blockedTermsFound.join( u"\", \"")); From 56ba1ca2ee6cc7e06be1d03750f787daf39519f8 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Wed, 6 Nov 2024 18:06:49 +0100 Subject: [PATCH 5/5] oopsie 2 --- src/providers/twitch/TwitchIrcServer.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/providers/twitch/TwitchIrcServer.cpp b/src/providers/twitch/TwitchIrcServer.cpp index e61cdb1db..de65ef845 100644 --- a/src/providers/twitch/TwitchIrcServer.cpp +++ b/src/providers/twitch/TwitchIrcServer.cpp @@ -505,21 +505,22 @@ void TwitchIrcServer::initialize() if (hideBlockedTerms) { action.reason = - u"matches %1 blocked term%2"_s.arg( - numBlockedTermsMatched, - numBlockedTermsMatched > 1 ? u"s" - : ""); + u"matches %1 blocked term%2"_s + .arg(numBlockedTermsMatched) + .arg(numBlockedTermsMatched > 1 + ? u"s" + : u""); } else { action.reason = u"matches %1 blocked term%2 \"%3\""_s - .arg(numBlockedTermsMatched, - numBlockedTermsMatched > 1 + .arg(numBlockedTermsMatched) + .arg(numBlockedTermsMatched > 1 ? u"s" - : "", - msg.blockedTermsFound.join( - u"\", \"")); + : u"") + .arg(msg.blockedTermsFound.join( + u"\", \"")); } } else