Implement custom bit badges

Fixes #226
This commit is contained in:
Rasmus Karlsson 2018-01-12 22:38:00 +01:00
parent 584e6e5643
commit 4cbc3b8b61

View file

@ -507,21 +507,22 @@ void TwitchMessageBuilder::parseTwitchBadges()
QString cheerAmountQS = badge.mid(5); QString cheerAmountQS = badge.mid(5);
std::string versionKey = cheerAmountQS.toStdString(); std::string versionKey = cheerAmountQS.toStdString();
// Try to fetch channel-specific bit badge
try { try {
auto &badgeSet = resourceManager.badgeSets.at("bits"); const auto &badge = channelResources.badgeSets.at("bits").versions.at(versionKey);
this->append<ImageElement>(*(badge.badgeImage1x), MessageElement::BadgeVanity);
try { continue;
auto &badgeVersion = badgeSet.versions.at(versionKey); } catch (const std::out_of_range &) {
// Channel does not contain a special bit badge for this version
this->append<ImageElement>(*badgeVersion.badgeImage1x,
MessageElement::BadgeVanity)
->setTooltip("Twitch " + QString::fromStdString(badgeVersion.title));
} catch (const std::exception &e) {
debug::Log("Exception caught: {} when trying to fetch badge version {} ",
e.what(), versionKey);
} }
} catch (const std::exception &e) {
debug::Log("No badge set with key bits. Exception: {}", e.what()); // Use default bit badge
try {
const auto &badge = resourceManager.badgeSets.at("bits").versions.at(versionKey);
this->append<ImageElement>(*(badge.badgeImage1x), MessageElement::BadgeVanity);
} catch (const std::out_of_range &) {
debug::Log("No default bit badge for version {} found", versionKey);
continue;
} }
} else if (badge == "staff/1") { } else if (badge == "staff/1") {
this->append<ImageElement>(*resourceManager.badgeStaff, this->append<ImageElement>(*resourceManager.badgeStaff,