fix: don't post contents of unknown commands to chat (#6272)
This commit is contained in:
@@ -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 =
|
||||
|
||||
Reference in New Issue
Block a user