mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
parent
3bfaba2d95
commit
63f85e9bee
4 changed files with 68 additions and 0 deletions
|
@ -60,6 +60,8 @@ Resources::Resources(EmoteManager &em, WindowManager &wm)
|
|||
|
||||
this->dynamicBadgesLoaded = true;
|
||||
});
|
||||
|
||||
this->loadChatterinoBadges();
|
||||
}
|
||||
|
||||
Resources::BadgeVersion::BadgeVersion(QJsonObject &&root, EmoteManager &emoteManager,
|
||||
|
@ -110,4 +112,36 @@ void Resources::loadChannelData(const std::string &roomID, bool bypassCache)
|
|||
});
|
||||
}
|
||||
|
||||
void Resources::loadChatterinoBadges()
|
||||
{
|
||||
this->chatterinoBadges.clear();
|
||||
|
||||
QString url = "https://fourtf.com/chatterino/badges.json";
|
||||
|
||||
util::urlFetchJSON(url, [this](QJsonObject &root) {
|
||||
QJsonArray badgeVariants = root.value("badges").toArray();
|
||||
|
||||
for (QJsonArray::iterator it = badgeVariants.begin(); it != badgeVariants.end(); ++it) {
|
||||
QJsonObject badgeVariant = it->toObject();
|
||||
const std::string badgeVariantTooltip =
|
||||
badgeVariant.value("tooltip").toString().toStdString();
|
||||
const QString &badgeVariantImageURL = badgeVariant.value("image").toString();
|
||||
|
||||
auto badgeVariantPtr = std::make_shared<ChatterinoBadge>(
|
||||
badgeVariantTooltip,
|
||||
new messages::LazyLoadedImage(this->emoteManager, this->windowManager,
|
||||
badgeVariantImageURL));
|
||||
|
||||
QJsonArray badgeVariantUsers = badgeVariant.value("users").toArray();
|
||||
|
||||
for (QJsonArray::iterator it = badgeVariantUsers.begin(); it != badgeVariantUsers.end();
|
||||
++it) {
|
||||
const std::string username = it->toString().toStdString();
|
||||
this->chatterinoBadges[username] =
|
||||
std::shared_ptr<ChatterinoBadge>(badgeVariantPtr);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "messages/lazyloadedimage.hpp"
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
namespace chatterino {
|
||||
|
@ -71,7 +72,23 @@ public:
|
|||
// channelId
|
||||
std::map<std::string, Channel> channels;
|
||||
|
||||
// Chatterino badges
|
||||
struct ChatterinoBadge {
|
||||
ChatterinoBadge(const std::string &_tooltip, messages::LazyLoadedImage *_image)
|
||||
: tooltip(_tooltip)
|
||||
, image(_image)
|
||||
{
|
||||
}
|
||||
|
||||
std::string tooltip;
|
||||
messages::LazyLoadedImage *image;
|
||||
};
|
||||
|
||||
// username
|
||||
std::map<std::string, std::shared_ptr<ChatterinoBadge>> chatterinoBadges;
|
||||
|
||||
void loadChannelData(const std::string &roomID, bool bypassCache = false);
|
||||
void loadChatterinoBadges();
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
|
|
@ -52,6 +52,8 @@ SharedMessage TwitchMessageBuilder::parse()
|
|||
|
||||
this->parseTwitchBadges();
|
||||
|
||||
this->parseChatterinoBadges();
|
||||
|
||||
if (this->args.includeChannelName) {
|
||||
this->parseChannelName();
|
||||
}
|
||||
|
@ -661,6 +663,20 @@ void TwitchMessageBuilder::parseTwitchBadges()
|
|||
}
|
||||
}
|
||||
|
||||
void TwitchMessageBuilder::parseChatterinoBadges()
|
||||
{
|
||||
auto &badges = this->resources.chatterinoBadges;
|
||||
auto it = badges.find(this->userName.toStdString());
|
||||
|
||||
if (it == badges.end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto badge = it->second;
|
||||
|
||||
this->appendWord(Word(badge->image, Word::BadgeChatterino, QString(), badge->tooltip.c_str()));
|
||||
}
|
||||
|
||||
// bool
|
||||
// sortTwitchEmotes(const std::pair<long int, LazyLoadedImage *> &a,
|
||||
// const std::pair<long int, LazyLoadedImage *> &b)
|
||||
|
|
|
@ -70,6 +70,7 @@ private:
|
|||
bool appendEmote(EmoteData &emoteData);
|
||||
|
||||
void parseTwitchBadges();
|
||||
void parseChatterinoBadges();
|
||||
};
|
||||
|
||||
} // namespace twitch
|
||||
|
|
Loading…
Reference in a new issue