Fall back to default subscriber badge if there's no other badge available

This commit is contained in:
Rasmus Karlsson 2017-11-04 17:22:53 +01:00
parent 49c2f442cb
commit ad8ee97de9
6 changed files with 26 additions and 19 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

View file

@ -32,6 +32,7 @@
<file>images/UserProfile_22x.png</file> <file>images/UserProfile_22x.png</file>
<file>images/VSO_Link_blue_16x.png</file> <file>images/VSO_Link_blue_16x.png</file>
<file>sounds/ping2.wav</file> <file>sounds/ping2.wav</file>
<file>images/subscriber.png</file>
</qresource> </qresource>
<qresource prefix="/qt/etc"> <qresource prefix="/qt/etc">
<file>qt.conf</file> <file>qt.conf</file>

View file

@ -19,8 +19,6 @@ namespace messages {
class Message; class Message;
} }
class IrcManager;
class Channel class Channel
{ {
public: public:

View file

@ -29,6 +29,7 @@ Resources::Resources(EmoteManager &em, WindowManager &wm)
, badgeBroadcaster(lli(em, wm, ":/images/broadcaster_bg.png")) , badgeBroadcaster(lli(em, wm, ":/images/broadcaster_bg.png"))
, badgePremium(lli(em, wm, ":/images/twitchprime_bg.png")) , badgePremium(lli(em, wm, ":/images/twitchprime_bg.png"))
, badgeVerified(lli(em, wm, ":/images/verified.png", 0.25)) , badgeVerified(lli(em, wm, ":/images/verified.png", 0.25))
, badgeSubscriber(lli(em, wm, ":/images/subscriber.png", 0.25))
, cheerBadge100000(lli(em, wm, ":/images/cheer100000")) , cheerBadge100000(lli(em, wm, ":/images/cheer100000"))
, cheerBadge10000(lli(em, wm, ":/images/cheer10000")) , cheerBadge10000(lli(em, wm, ":/images/cheer10000"))
, cheerBadge5000(lli(em, wm, ":/images/cheer5000")) , cheerBadge5000(lli(em, wm, ":/images/cheer5000"))

View file

@ -27,6 +27,7 @@ public:
messages::LazyLoadedImage *badgeBroadcaster; messages::LazyLoadedImage *badgeBroadcaster;
messages::LazyLoadedImage *badgePremium; messages::LazyLoadedImage *badgePremium;
messages::LazyLoadedImage *badgeVerified; messages::LazyLoadedImage *badgeVerified;
messages::LazyLoadedImage *badgeSubscriber;
messages::LazyLoadedImage *cheerBadge100000; messages::LazyLoadedImage *cheerBadge100000;
messages::LazyLoadedImage *cheerBadge10000; messages::LazyLoadedImage *cheerBadge10000;

View file

@ -619,25 +619,31 @@ void TwitchMessageBuilder::parseTwitchBadges()
continue; continue;
} }
try { auto badgeSetIt = channelResources.badgeSets.find("subscriber");
const auto &badgeSet = channelResources.badgeSets.at("subscriber"); if (badgeSetIt == channelResources.badgeSets.end()) {
// Fall back to default badge
std::string versionKey = badge.mid(11).toStdString(); appendWord(Word(this->resources.badgeSubscriber, Word::Type::BadgeSubscription,
QString(), QString("Twitch Subscriber")));
try { continue;
auto &badgeVersion = badgeSet.versions.at(versionKey);
appendWord(
Word(badgeVersion.badgeImage1x, Word::Type::BadgeSubscription, QString(),
QString("Twitch " + QString::fromStdString(badgeVersion.title))));
} catch (const std::exception &e) {
qDebug() << "Exception caught:" << e.what()
<< "when trying to fetch badge version " << versionKey.c_str();
}
} catch (const std::exception &e) {
qDebug() << "No channel badge set with key `subscriber`. Exception: " << e.what();
} }
const auto &badgeSet = badgeSetIt->second;
std::string versionKey = badge.mid(11).toStdString();
auto badgeVersionIt = badgeSet.versions.find(versionKey);
if (badgeVersionIt == badgeSet.versions.end()) {
// Fall back to default badge
appendWord(Word(this->resources.badgeSubscriber, Word::Type::BadgeSubscription,
QString(), QString("Twitch Subscriber")));
continue;
}
auto &badgeVersion = badgeVersionIt->second;
appendWord(Word(badgeVersion.badgeImage1x, Word::Type::BadgeSubscription, QString(),
QString("Twitch " + QString::fromStdString(badgeVersion.title))));
} else { } else {
if (!this->resources.dynamicBadgesLoaded) { if (!this->resources.dynamicBadgesLoaded) {
// Do nothing // Do nothing