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
+33 -1
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;
}