Move bttv emotes to its own class
This commit is contained in:
@@ -26,13 +26,6 @@ namespace singletons {
|
||||
|
||||
namespace {
|
||||
|
||||
QString GetBTTVEmoteLink(QString urlTemplate, const QString &id, const QString &emoteScale)
|
||||
{
|
||||
urlTemplate.detach();
|
||||
|
||||
return urlTemplate.replace("{{id}}", id).replace("{{image}}", emoteScale);
|
||||
}
|
||||
|
||||
QString GetFFZEmoteLink(const QJsonObject &urls, const QString &emoteScale)
|
||||
{
|
||||
auto emote = urls.value(emoteScale);
|
||||
@@ -82,71 +75,10 @@ void EmoteManager::initialize()
|
||||
});
|
||||
|
||||
this->loadEmojis();
|
||||
this->loadBTTVEmotes();
|
||||
this->bttv.loadGlobalEmotes();
|
||||
this->loadFFZEmotes();
|
||||
}
|
||||
|
||||
void EmoteManager::reloadBTTVChannelEmotes(const QString &channelName,
|
||||
std::weak_ptr<util::EmoteMap> _map)
|
||||
{
|
||||
printf("[EmoteManager] Reload BTTV Channel Emotes for channel %s\n", qPrintable(channelName));
|
||||
|
||||
QString url("https://api.betterttv.net/2/channels/" + channelName);
|
||||
|
||||
debug::Log("Request bttv channel emotes for {}", channelName);
|
||||
|
||||
util::NetworkRequest req(url);
|
||||
req.setCaller(QThread::currentThread());
|
||||
req.setTimeout(3000);
|
||||
req.getJSON([this, channelName, _map](QJsonObject &rootNode) {
|
||||
auto map = _map.lock();
|
||||
|
||||
if (_map.expired()) {
|
||||
return;
|
||||
}
|
||||
|
||||
map->clear();
|
||||
|
||||
auto emotesNode = rootNode.value("emotes").toArray();
|
||||
|
||||
QString linkTemplate = "https:" + rootNode.value("urlTemplate").toString();
|
||||
|
||||
std::vector<std::string> codes;
|
||||
for (const QJsonValue &emoteNode : emotesNode) {
|
||||
QJsonObject emoteObject = emoteNode.toObject();
|
||||
|
||||
QString id = emoteObject.value("id").toString();
|
||||
QString code = emoteObject.value("code").toString();
|
||||
// emoteObject.value("imageType").toString();
|
||||
|
||||
auto emote = this->getBTTVChannelEmoteFromCaches().getOrAdd(id, [&] {
|
||||
util::EmoteData emoteData;
|
||||
QString link = linkTemplate;
|
||||
link.detach();
|
||||
emoteData.image1x = new Image(link.replace("{{id}}", id).replace("{{image}}", "1x"),
|
||||
1, code, code + "<br />Channel BTTV Emote");
|
||||
link = linkTemplate;
|
||||
link.detach();
|
||||
emoteData.image2x = new Image(link.replace("{{id}}", id).replace("{{image}}", "2x"),
|
||||
0.5, code, code + "<br />Channel BTTV Emote");
|
||||
link = linkTemplate;
|
||||
link.detach();
|
||||
emoteData.image3x = new Image(link.replace("{{id}}", id).replace("{{image}}", "3x"),
|
||||
0.25, code, code + "<br />Channel BTTV Emote");
|
||||
emoteData.pageLink = "https://manage.betterttv.net/emotes/" + id;
|
||||
|
||||
return emoteData;
|
||||
});
|
||||
|
||||
this->bttvChannelEmotes.insert(code, emote);
|
||||
map->insert(code, emote);
|
||||
codes.push_back(code.toStdString());
|
||||
}
|
||||
|
||||
this->bttvChannelEmoteCodes[channelName.toStdString()] = codes;
|
||||
});
|
||||
}
|
||||
|
||||
void EmoteManager::reloadFFZChannelEmotes(const QString &channelName,
|
||||
std::weak_ptr<util::EmoteMap> _map)
|
||||
{
|
||||
@@ -210,11 +142,6 @@ util::EmoteMap &EmoteManager::getChatterinoEmotes()
|
||||
return _chatterinoEmotes;
|
||||
}
|
||||
|
||||
util::EmoteMap &EmoteManager::getBTTVChannelEmoteFromCaches()
|
||||
{
|
||||
return _bttvChannelEmoteFromCaches;
|
||||
}
|
||||
|
||||
util::EmojiMap &EmoteManager::getEmojis()
|
||||
{
|
||||
return this->emojis;
|
||||
@@ -400,41 +327,6 @@ QString EmoteManager::replaceShortCodes(const QString &text)
|
||||
return ret;
|
||||
}
|
||||
|
||||
void EmoteManager::loadBTTVEmotes()
|
||||
{
|
||||
QString url("https://api.betterttv.net/2/emotes");
|
||||
|
||||
util::NetworkRequest req(url);
|
||||
req.setCaller(QThread::currentThread());
|
||||
req.setTimeout(30000);
|
||||
req.setUseQuickLoadCache(true);
|
||||
req.getJSON([this](QJsonObject &root) {
|
||||
auto emotes = root.value("emotes").toArray();
|
||||
|
||||
QString urlTemplate = "https:" + root.value("urlTemplate").toString();
|
||||
|
||||
std::vector<std::string> codes;
|
||||
for (const QJsonValue &emote : emotes) {
|
||||
QString id = emote.toObject().value("id").toString();
|
||||
QString code = emote.toObject().value("code").toString();
|
||||
|
||||
util::EmoteData emoteData;
|
||||
emoteData.image1x = new Image(GetBTTVEmoteLink(urlTemplate, id, "1x"), 1, code,
|
||||
code + "<br />Global BTTV Emote");
|
||||
emoteData.image2x = new Image(GetBTTVEmoteLink(urlTemplate, id, "2x"), 0.5, code,
|
||||
code + "<br />Global BTTV Emote");
|
||||
emoteData.image3x = new Image(GetBTTVEmoteLink(urlTemplate, id, "3x"), 0.25, code,
|
||||
code + "<br />Global BTTV Emote");
|
||||
emoteData.pageLink = "https://manage.betterttv.net/emotes/" + id;
|
||||
|
||||
this->bttvGlobalEmotes.insert(code, emoteData);
|
||||
codes.push_back(code.toStdString());
|
||||
}
|
||||
|
||||
this->bttvGlobalEmoteCodes = codes;
|
||||
});
|
||||
}
|
||||
|
||||
void EmoteManager::loadFFZEmotes()
|
||||
{
|
||||
QString url("https://api.frankerfacez.com/v1/set/global");
|
||||
|
||||
Reference in New Issue
Block a user