Fixed cheers not showing up in chat Fixes #1031

This commit is contained in:
apa420
2019-09-08 12:45:25 +02:00
parent e4e863bae5
commit 48fcc1a1a1
5 changed files with 114 additions and 73 deletions
+55 -13
View File
@@ -739,22 +739,22 @@ void TwitchChannel::refreshBadges()
void TwitchChannel::refreshCheerEmotes()
{
/*auto url = Url{"https://api.twitch.tv/kraken/bits/actions?channel_id=" +
this->getRoomId()};
auto request = NetworkRequest::twitchRequest(url.string);
request.setCaller(QThread::currentThread());
request.onSuccess(
[this, weak = weakOf<Channel>(this)](auto result) -> Outcome {
QString url("https://api.twitch.tv/kraken/bits/actions?channel_id=" +
this->roomId());
NetworkRequest::twitchRequest(url)
.onSuccess([this,
weak = weakOf<Channel>(this)](auto result) -> Outcome {
auto cheerEmoteSets = ParseCheermoteSets(result.parseRapidJson());
std::vector<CheerEmoteSet> emoteSets;
for (auto &set : cheerEmoteSets) {
for (auto &set : cheerEmoteSets)
{
auto cheerEmoteSet = CheerEmoteSet();
cheerEmoteSet.regex = QRegularExpression(
"^" + set.prefix.toLower() + "([1-9][0-9]*)$");
for (auto &tier : set.tiers) {
for (auto &tier : set.tiers)
{
CheerEmote cheerEmote;
cheerEmote.color = QColor(tier.color);
@@ -795,10 +795,8 @@ void TwitchChannel::refreshCheerEmotes()
*this->cheerEmoteSets_.access() = std::move(emoteSets);
return Success;
});
request.execute();
*/
})
.execute();
}
boost::optional<EmotePtr> TwitchChannel::twitchBadge(
@@ -825,4 +823,48 @@ boost::optional<EmotePtr> TwitchChannel::ffzCustomModBadge() const
return boost::none;
}
boost::optional<std::tuple<boost::optional<EmotePtr>, boost::optional<EmotePtr>,
boost::optional<QColor>>>
TwitchChannel::cheerEmote(const QString &string)
{
auto sets = this->cheerEmoteSets_.access();
for (const auto &set : *sets)
{
auto match = set.regex.match(string.toLower());
if (!match.hasMatch())
{
continue;
}
QString amount = match.captured(1);
bool ok = false;
int bitAmount = amount.toInt(&ok);
if (!ok)
{
log("Error parsing bit amount in cheerEmote");
}
for (const auto &emote : set.cheerEmotes)
{
if (amount >= emote.minBits)
{
using OPEP = boost::optional<EmotePtr>;
std::tuple<OPEP, OPEP, boost::optional<QColor>> retval;
if (emote.staticEmote)
{
std::get<0>(retval) = emote.staticEmote;
}
if (emote.animatedEmote)
{
std::get<1>(retval) = emote.animatedEmote;
}
if (emote.color != QColor())
{
std::get<2>(retval) = emote.color;
}
return retval;
}
}
}
return boost::none;
}
} // namespace chatterino