Skip to content

Commit

Permalink
IRC Tag fuckery (SevenTV#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mm2PL authored Jun 15, 2021
1 parent d36fb32 commit f753de5
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Major: Add 7TV emotes from Chatterino7 (Mm2PL/Dankerino#79)
- Minor: Move Dankerino settings to a separate tab (Mm2PL/Dankerino#84)
- Minor: Add advanced IRC tag related settings (Mm2PL/Dankerino#86)
- Minor: Allow for adjusting rate limit settings.

### Chatterino
Expand Down
39 changes: 39 additions & 0 deletions src/providers/twitch/TwitchMessageBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,23 @@ const QSet<QString> zeroWidthEmotes{
"ReinDeer", "CandyCane", "cvMask", "cvHazmat",
};

bool isAbnormalNonce(const QString &nonce)
{
// matches /[0-9a-f]{32}/
if (nonce.size() != 32)
{
return true;
}
for (const auto letter : nonce)
{
if (('0' > letter || letter > '9') && ('a' > letter || letter > 'f'))
{
return true;
}
}
return false;
}

} // namespace

namespace chatterino {
Expand Down Expand Up @@ -211,6 +228,28 @@ MessagePtr TwitchMessageBuilder::build()
this->appendChannelPointRewardMessage(reward.get(), this);
}
}
if (this->tags.contains("client-nonce"))
{
auto isAbnormal =
isAbnormalNonce(this->tags["client-nonce"].toString());
if (isAbnormal && getSettings()->abnormalNonceDetection)
{
this->emplace<TimestampElement>();
this->emplace<TextElement>(
"Abnormal nonce:", MessageElementFlag::ChannelPointReward,
MessageColor::System);
this->emplace<TextElement>(this->tags["client-nonce"].toString(),
MessageElementFlag::ChannelPointReward,
MessageColor::Text);
this->emplace<LinebreakElement>(
MessageElementFlag::ChannelPointReward);
}
else if (!isAbnormal && getSettings()->normalNonceDetection)
{
this->emplace<TextElement>("*", MessageElementFlag::Text,
MessageColor(QColor(255, 163, 11)));
}
}

this->appendChannelName();

Expand Down
3 changes: 3 additions & 0 deletions src/singletons/Settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,9 @@ class Settings : public ABSettings, public ConcurrentSettings
"/misc/twitch/lowRateLimitDelay",
1100,
};
BoolSetting abnormalNonceDetection = {"/misc/abnormalNonceDetection",
false};
BoolSetting normalNonceDetection = {"/misc/normalNonceDetection", false};

BoolSetting dankerinoThreeLetterApiEasterEgg = {
"/misc/dankerinoThreeLetterApiEasterEgg", false};
Expand Down
12 changes: 10 additions & 2 deletions src/widgets/settingspages/DankerinoPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,17 @@ void DankerinoPage::initLayout(GeneralPageView &layout)

if (s.dankerinoThreeLetterApiEasterEgg)
{
layout.addCheckbox("Click to disable GraphQL easter egg and "
"advanced settings "
"(requires restart)",
s.dankerinoThreeLetterApiEasterEgg);
layout.addTitle("Random 'hacks'");
layout.addCheckbox("Abnormal nonce detection",
s.abnormalNonceDetection);
layout.addCheckbox(
"Click to disable GraphQL easter egg (requires restart)",
s.dankerinoThreeLetterApiEasterEgg);
"Webchat detection. Adds a little orange asterisk before the "
"message timestamp if it was sent from webchat.",
s.normalNonceDetection);
}
layout.addStretch();
// invisible element for width
Expand Down

0 comments on commit f753de5

Please sign in to comment.