Check for ignored phrases/users in channel point redemptions (#3102)

This commit is contained in:
pajlada 2021-08-01 15:44:04 +02:00 committed by GitHub
parent 77f683577f
commit 784fdd28b2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 108 additions and 56 deletions

View file

@ -16,6 +16,7 @@
- Bugfix: Copy buttons in usercard now show properly in light mode (#3057) - Bugfix: Copy buttons in usercard now show properly in light mode (#3057)
- Bugfix: Fixed comma appended to username completion when not at the beginning of the message. (#3060) - Bugfix: Fixed comma appended to username completion when not at the beginning of the message. (#3060)
- Bugfix: Fixed bug misplacing chat when zooming on Chrome with Chatterino Native Host extension (#1936) - Bugfix: Fixed bug misplacing chat when zooming on Chrome with Chatterino Native Host extension (#1936)
- Bugfix: Channel point redemptions from ignored users are now properly blocked. (#3102)
- Dev: Ubuntu packages are now available (#2936) - Dev: Ubuntu packages are now available (#2936)
- Dev: Disabled update checker on Flatpak. (#3051) - Dev: Disabled update checker on Flatpak. (#3051)
- Dev: Add logging for HTTP requests (#2991) - Dev: Add logging for HTTP requests (#2991)

View file

@ -159,6 +159,7 @@ SOURCES += \
src/controllers/highlights/HighlightModel.cpp \ src/controllers/highlights/HighlightModel.cpp \
src/controllers/highlights/HighlightPhrase.cpp \ src/controllers/highlights/HighlightPhrase.cpp \
src/controllers/highlights/UserHighlightModel.cpp \ src/controllers/highlights/UserHighlightModel.cpp \
src/controllers/ignores/IgnoreController.cpp \
src/controllers/ignores/IgnoreModel.cpp \ src/controllers/ignores/IgnoreModel.cpp \
src/controllers/moderationactions/ModerationAction.cpp \ src/controllers/moderationactions/ModerationAction.cpp \
src/controllers/moderationactions/ModerationActionModel.cpp \ src/controllers/moderationactions/ModerationActionModel.cpp \

View file

@ -88,6 +88,8 @@ set(SOURCE_FILES
controllers/highlights/UserHighlightModel.cpp controllers/highlights/UserHighlightModel.cpp
controllers/highlights/UserHighlightModel.hpp controllers/highlights/UserHighlightModel.hpp
controllers/ignores/IgnoreController.cpp
controllers/ignores/IgnoreController.hpp
controllers/ignores/IgnoreModel.cpp controllers/ignores/IgnoreModel.cpp
controllers/ignores/IgnoreModel.hpp controllers/ignores/IgnoreModel.hpp

View file

@ -0,0 +1,63 @@
#include "controllers/ignores/IgnoreController.hpp"
#include "common/QLogging.hpp"
#include "controllers/ignores/IgnorePhrase.hpp"
#include "singletons/Settings.hpp"
namespace chatterino {
bool isIgnoredMessage(IgnoredMessageParameters &&params)
{
if (!params.message.isEmpty())
{
// TODO(pajlada): Do we need to check if the phrase is valid first?
auto phrases = getCSettings().ignoredMessages.readOnly();
for (const auto &phrase : *phrases)
{
if (phrase.isBlock() && phrase.isMatch(params.message))
{
qCDebug(chatterinoMessage)
<< "Blocking message because it contains ignored phrase"
<< phrase.getPattern();
return true;
}
}
}
if (!params.twitchUserID.isEmpty() &&
getSettings()->enableTwitchBlockedUsers)
{
auto sourceUserID = params.twitchUserID;
auto blocks =
getApp()->accounts->twitch.getCurrent()->accessBlockedUserIds();
if (auto it = blocks->find(sourceUserID); it != blocks->end())
{
switch (static_cast<ShowIgnoredUsersMessages>(
getSettings()->showBlockedUsersMessages.getValue()))
{
case ShowIgnoredUsersMessages::IfModerator:
if (params.isMod || params.isBroadcaster)
{
return false;
}
break;
case ShowIgnoredUsersMessages::IfBroadcaster:
if (params.isBroadcaster)
{
return false;
}
break;
case ShowIgnoredUsersMessages::Never:
break;
}
return true;
}
}
return false;
}
} // namespace chatterino

View file

@ -1,7 +1,19 @@
#pragma once #pragma once
#include <QString>
namespace chatterino { namespace chatterino {
enum class ShowIgnoredUsersMessages { Never, IfModerator, IfBroadcaster }; enum class ShowIgnoredUsersMessages { Never, IfModerator, IfBroadcaster };
struct IgnoredMessageParameters {
QString message;
QString twitchUserID;
bool isMod;
bool isBroadcaster;
};
bool isIgnoredMessage(IgnoredMessageParameters &&params);
} // namespace chatterino } // namespace chatterino

View file

@ -2,6 +2,7 @@
#include "Application.hpp" #include "Application.hpp"
#include "common/QLogging.hpp" #include "common/QLogging.hpp"
#include "controllers/ignores/IgnoreController.hpp"
#include "controllers/ignores/IgnorePhrase.hpp" #include "controllers/ignores/IgnorePhrase.hpp"
#include "messages/Message.hpp" #include "messages/Message.hpp"
#include "messages/MessageElement.hpp" #include "messages/MessageElement.hpp"
@ -104,20 +105,9 @@ void SharedMessageBuilder::parse()
bool SharedMessageBuilder::isIgnored() const bool SharedMessageBuilder::isIgnored() const
{ {
// TODO(pajlada): Do we need to check if the phrase is valid first? return isIgnoredMessage({
auto phrases = getCSettings().ignoredMessages.readOnly(); /*.message = */ this->originalMessage_,
for (const auto &phrase : *phrases) });
{
if (phrase.isBlock() && phrase.isMatch(this->originalMessage_))
{
qCDebug(chatterinoMessage)
<< "Blocking message because it contains ignored phrase"
<< phrase.getPattern();
return true;
}
}
return false;
} }
void SharedMessageBuilder::parseUsernameColor() void SharedMessageBuilder::parseUsernameColor()

View file

@ -286,7 +286,8 @@ void TwitchChannel::addChannelPointReward(const ChannelPointReward &reward)
if (!reward.isUserInputRequired) if (!reward.isUserInputRequired)
{ {
MessageBuilder builder; MessageBuilder builder;
TwitchMessageBuilder::appendChannelPointRewardMessage(reward, &builder); TwitchMessageBuilder::appendChannelPointRewardMessage(
reward, &builder, this->isMod(), this->isBroadcaster());
this->addMessage(builder.release()); this->addMessage(builder.release());
return; return;
} }

View file

@ -114,44 +114,12 @@ TwitchMessageBuilder::TwitchMessageBuilder(
bool TwitchMessageBuilder::isIgnored() const bool TwitchMessageBuilder::isIgnored() const
{ {
if (SharedMessageBuilder::isIgnored()) return isIgnoredMessage({
{ /*.message = */ this->originalMessage_,
return true; /*.twitchUserID = */ this->tags.value("user-id").toString(),
} /*.isMod = */ this->channel->isMod(),
/*.isBroadcaster = */ this->channel->isBroadcaster(),
auto app = getApp(); });
if (getSettings()->enableTwitchBlockedUsers &&
this->tags.contains("user-id"))
{
auto sourceUserID = this->tags.value("user-id").toString();
auto blocks =
app->accounts->twitch.getCurrent()->accessBlockedUserIds();
if (auto it = blocks->find(sourceUserID); it != blocks->end())
{
switch (static_cast<ShowIgnoredUsersMessages>(
getSettings()->showBlockedUsersMessages.getValue()))
{
case ShowIgnoredUsersMessages::IfModerator:
if (this->channel->isMod() ||
this->channel->isBroadcaster())
return false;
break;
case ShowIgnoredUsersMessages::IfBroadcaster:
if (this->channel->isBroadcaster())
return false;
break;
case ShowIgnoredUsersMessages::Never:
break;
}
return true;
}
}
return false;
} }
void TwitchMessageBuilder::triggerHighlights() void TwitchMessageBuilder::triggerHighlights()
@ -190,7 +158,9 @@ MessagePtr TwitchMessageBuilder::build()
this->args.channelPointRewardId); this->args.channelPointRewardId);
if (reward) if (reward)
{ {
this->appendChannelPointRewardMessage(reward.get(), this); this->appendChannelPointRewardMessage(
reward.get(), this, this->channel->isMod(),
this->channel->isBroadcaster());
} }
} }
@ -1261,8 +1231,19 @@ Outcome TwitchMessageBuilder::tryParseCheermote(const QString &string)
} }
void TwitchMessageBuilder::appendChannelPointRewardMessage( void TwitchMessageBuilder::appendChannelPointRewardMessage(
const ChannelPointReward &reward, MessageBuilder *builder) const ChannelPointReward &reward, MessageBuilder *builder, bool isMod,
bool isBroadcaster)
{ {
if (isIgnoredMessage({
/*.message = */ "",
/*.twitchUserID = */ reward.user.id,
/*.isMod = */ isMod,
/*.isBroadcaster = */ isBroadcaster,
}))
{
return;
}
builder->emplace<TimestampElement>(); builder->emplace<TimestampElement>();
QString redeemed = "Redeemed"; QString redeemed = "Redeemed";
QStringList textList; QStringList textList;

View file

@ -46,7 +46,8 @@ public:
MessagePtr build() override; MessagePtr build() override;
static void appendChannelPointRewardMessage( static void appendChannelPointRewardMessage(
const ChannelPointReward &reward, MessageBuilder *builder); const ChannelPointReward &reward, MessageBuilder *builder, bool isMod,
bool isBroadcaster);
// Message in the /live chat for channel going live // Message in the /live chat for channel going live
static void liveMessage(const QString &channelName, static void liveMessage(const QString &channelName,