mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
parent
323cdc5561
commit
3e91340788
2 changed files with 28 additions and 11 deletions
|
@ -86,13 +86,15 @@ void Resources::loadChannelData(const std::string &roomID, bool bypassCache)
|
||||||
QString url = "https://badges.twitch.tv/v1/badges/channels/" + QString::fromStdString(roomID) +
|
QString url = "https://badges.twitch.tv/v1/badges/channels/" + QString::fromStdString(roomID) +
|
||||||
"/display?language=en";
|
"/display?language=en";
|
||||||
|
|
||||||
util::urlFetchJSON(url, [this](QJsonObject &root) {
|
util::urlFetchJSON(url, [this, roomID](QJsonObject &root) {
|
||||||
QJsonObject sets = root.value("badge_sets").toObject();
|
QJsonObject sets = root.value("badge_sets").toObject();
|
||||||
|
|
||||||
|
Resources::Channel &ch = this->channels[roomID];
|
||||||
|
|
||||||
for (QJsonObject::iterator it = sets.begin(); it != sets.end(); ++it) {
|
for (QJsonObject::iterator it = sets.begin(); it != sets.end(); ++it) {
|
||||||
QJsonObject versions = it.value().toObject().value("versions").toObject();
|
QJsonObject versions = it.value().toObject().value("versions").toObject();
|
||||||
|
|
||||||
auto &badgeSet = this->badgeSets[it.key().toStdString()];
|
auto &badgeSet = ch.badgeSets[it.key().toStdString()];
|
||||||
auto &versionsMap = badgeSet.versions;
|
auto &versionsMap = badgeSet.versions;
|
||||||
|
|
||||||
for (auto versionIt = std::begin(versions); versionIt != std::end(versions);
|
for (auto versionIt = std::begin(versions); versionIt != std::end(versions);
|
||||||
|
@ -104,7 +106,7 @@ void Resources::loadChannelData(const std::string &roomID, bool bypassCache)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this->dynamicBadgesLoaded = true;
|
ch.loaded = true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -425,15 +425,30 @@ void TwitchMessageBuilder::appendTwitchBadges(const QStringList &badges, Resourc
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
} else if (badge.startsWith("subscriber/")) {
|
} else if (badge.startsWith("subscriber/")) {
|
||||||
qDebug() << "Subscriber badge:" << badge;
|
if (channelResources.loaded == false) {
|
||||||
int index = badge.midRef(11).toInt();
|
qDebug() << "Channel resources are not loaded, can't add the subscriber badge";
|
||||||
// TODO: Implement subscriber badges here
|
continue;
|
||||||
switch (index) {
|
|
||||||
default: {
|
|
||||||
// printf("[TwitchMessageBuilder] Unhandled subscriber badge index: %d\n",
|
|
||||||
// index);
|
|
||||||
} break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const auto &badgeSet = channelResources.badgeSets.at("subscriber");
|
||||||
|
|
||||||
|
std::string versionKey = badge.mid(11).toStdString();
|
||||||
|
|
||||||
|
try {
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (!resources.dynamicBadgesLoaded) {
|
if (!resources.dynamicBadgesLoaded) {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
|
|
Loading…
Reference in a new issue