Various bits fixes (#1443)

We now make sure we don't render any fake bits
Bits now show their real value properly
This commit is contained in:
apa420 2019-12-19 21:36:02 +01:00 committed by pajlada
parent 11442bba20
commit 0d227ab2f5
4 changed files with 36 additions and 1 deletions

View file

@ -759,6 +759,7 @@ void TwitchChannel::refreshCheerEmotes()
cheerEmote.color = QColor(tier.color);
cheerEmote.minBits = tier.minBits;
cheerEmote.regex = cheerEmoteSet.regex;
// TODO(pajlada): We currently hardcode dark here :|
// We will continue to do so for now since we haven't had to

View file

@ -18,6 +18,7 @@ using EmotePtr = std::shared_ptr<const Emote>;
struct CheerEmote {
QColor color;
int minBits;
QRegularExpression regex;
EmotePtr animatedEmote;
EmotePtr staticEmote;

View file

@ -346,6 +346,7 @@ MessagePtr TwitchMessageBuilder::build()
if (iterator != this->tags.end())
{
this->hasBits_ = true;
this->bitsLeft = iterator.value().toInt();
this->bits = iterator.value().toString();
}
@ -1263,12 +1264,41 @@ void TwitchMessageBuilder::appendChatterinoBadges()
Outcome TwitchMessageBuilder::tryParseCheermote(const QString &string)
{
if (this->bitsLeft == 0)
{
return Failure;
}
auto cheerOpt = this->twitchChannel->cheerEmote(string);
if (!cheerOpt)
{
return Failure;
}
auto &cheerEmote = *cheerOpt;
auto match = cheerEmote.regex.match(string);
if (!match.hasMatch())
{
return Failure;
}
int cheerValue = match.captured(1).toInt();
if (this->bitsLeft >= cheerValue)
{
this->bitsLeft -= cheerValue;
}
else
{
QString newString = string;
newString.chop(QString::number(cheerValue).length());
newString += QString::number(cheerValue - this->bitsLeft);
return tryParseCheermote(newString);
}
if (cheerEmote.staticEmote)
{
this->emplace<EmoteElement>(cheerEmote.staticEmote,
@ -1281,9 +1311,11 @@ Outcome TwitchMessageBuilder::tryParseCheermote(const QString &string)
}
if (cheerEmote.color != QColor())
{
this->emplace<TextElement>(this->bits, MessageElementFlag::BitsAmount,
this->emplace<TextElement>(match.captured(1),
MessageElementFlag::BitsAmount,
cheerEmote.color);
}
return Success;
}

View file

@ -81,6 +81,7 @@ private:
QString roomID_;
bool hasBits_ = false;
QString bits;
int bitsLeft;
bool historicalMessage_ = false;
QString userId_;