fix: don't post contents of unknown commands to chat (#6272)

This commit is contained in:
pajlada
2025-06-15 15:46:24 +02:00
committed by GitHub
parent 7f9dfd4aea
commit f26d6d57de
9 changed files with 126 additions and 20 deletions
+1 -1
View File
@@ -130,7 +130,7 @@ public:
return this->getEnum();
}
Enum getEnum()
Enum getEnum() const
{
return qmagicenum::enumCast<Enum>(this->getValue(),
qmagicenum::CASE_INSENSITIVE)
+32 -1
View File
@@ -61,6 +61,22 @@ namespace chatterino {
using namespace literals;
namespace detail {
bool isUnknownCommand(const QString &text)
{
static QRegularExpression isUnknownCommand(
R"(^(?:\.|\/)(?!me\s|\s))", QRegularExpression::CaseInsensitiveOption);
auto match = isUnknownCommand.match(text);
return match.hasMatch();
}
} // namespace detail
using detail::isUnknownCommand;
namespace {
#if QT_VERSION < QT_VERSION_CHECK(6, 1, 0)
const QString MAGIC_MESSAGE_SUFFIX = QString((const char *)u8" \U000E0000");
@@ -91,6 +107,7 @@ constexpr auto MAX_CHATTERS_TO_FETCH = 5000;
// From Twitch docs - expected size for a badge (1x)
constexpr QSize BASE_BADGE_SIZE(18, 18);
} // namespace
TwitchChannel::TwitchChannel(const QString &name)
@@ -794,6 +811,13 @@ void TwitchChannel::sendMessage(const QString &message)
return;
}
if (getSettings()->shouldSendHelixChat() && isUnknownCommand(parsedMessage))
{
this->addSystemMessage(QString("%1 is not a known command.")
.arg(parsedMessage.split(' ').first()));
return;
}
bool messageSent = false;
this->sendMessageSignal.invoke(this->getName(), parsedMessage, messageSent);
this->updateSevenTVActivity();
@@ -828,6 +852,13 @@ void TwitchChannel::sendReply(const QString &message, const QString &replyId)
return;
}
if (getSettings()->shouldSendHelixChat() && isUnknownCommand(parsedMessage))
{
this->addSystemMessage(QString("%1 is not a known command.")
.arg(parsedMessage.split(' ').first()));
return;
}
bool messageSent = false;
this->sendReplySignal.invoke(this->getName(), parsedMessage, replyId,
messageSent);
@@ -1452,7 +1483,7 @@ void TwitchChannel::loadRecentMessagesReconnect()
int limit = getSettings()->twitchMessageHistoryLimit.getValue();
if (this->lastConnectedAt_.has_value())
{
// calculate how many messages could have occured
// calculate how many messages could have occurred
// while we were not connected to the channel
// assuming a maximum of 10 messages per second
const auto secondsSinceDisconnect =
+18
View File
@@ -64,6 +64,24 @@ class TwitchAccount;
const int MAX_QUEUED_REDEMPTIONS = 16;
namespace detail {
/// isUnknownCommand checks if the given text contains a command that should not be forwarded to Twitch
///
/// "/ hello" should be allowed
/// ". hello" should be allowed
/// "/me hello" should be allowed
/// ".me hello" should be allowed
/// "/mebadcommand hello" should NOT be allowed
/// ".mebadcommand hello" should NOT be allowed
/// "/badcommand hello" should NOT be allowed
/// "/badcommand hello" should NOT be allowed
/// ".@badcommand hello" should NOT be allowed
/// ".@badcommand hello" should NOT be allowed
bool isUnknownCommand(const QString &text);
} // namespace detail
class TwitchChannel final : public Channel, public ChannelChatters
{
public:
+2 -18
View File
@@ -129,22 +129,6 @@ void sendHelixMessage(const std::shared_ptr<TwitchChannel> &channel,
});
}
/// Returns true if chat messages should be sent over Helix
bool shouldSendHelixChat()
{
switch (getSettings()->chatSendProtocol)
{
case ChatSendProtocol::Helix:
return true;
case ChatSendProtocol::Default:
case ChatSendProtocol::IRC:
return false;
default:
assert(false && "Invalid chat protocol value");
return false;
}
}
} // namespace
namespace chatterino {
@@ -762,7 +746,7 @@ void TwitchIrcServer::onMessageSendRequested(
return;
}
if (shouldSendHelixChat())
if (getSettings()->shouldSendHelixChat())
{
sendHelixMessage(channel, message);
}
@@ -786,7 +770,7 @@ void TwitchIrcServer::onReplySendRequested(
return;
}
if (shouldSendHelixChat())
if (getSettings()->shouldSendHelixChat())
{
sendHelixMessage(channel, message, replyId);
}
+15
View File
@@ -283,6 +283,21 @@ void Settings::disableSave()
this->disableSaving = true;
}
bool Settings::shouldSendHelixChat() const
{
switch (this->chatSendProtocol.getEnum())
{
case ChatSendProtocol::Helix:
return true;
case ChatSendProtocol::Default:
case ChatSendProtocol::IRC:
return false;
default:
assert(false && "Invalid chat protocol value");
return false;
}
}
float Settings::getClampedUiScale() const
{
return std::clamp(this->uiScale.getValue(), 0.2F, 10.F);
+3
View File
@@ -145,6 +145,9 @@ public:
void disableSave();
/// Returns true if chat messages should be sent over Helix
bool shouldSendHelixChat() const;
FloatSetting uiScale = {"/appearance/uiScale2", 1};
BoolSetting windowTopMost = {"/appearance/windowAlwaysOnTop", false};