mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
added global ffz and bttv emotes
This commit is contained in:
parent
e0abfb9a1f
commit
fb14e86364
88
channel.cpp
88
channel.cpp
|
@ -24,6 +24,94 @@ Channel::Channel(const QString &channel)
|
|||
// }
|
||||
}
|
||||
|
||||
void
|
||||
Channel::reloadBttvEmotes()
|
||||
{
|
||||
QNetworkAccessManager *manager = new QNetworkAccessManager();
|
||||
|
||||
QUrl url("https://api.frankerfacez.com/v1/set/global");
|
||||
QNetworkRequest request(url);
|
||||
|
||||
QNetworkReply *reply = manager->get(request);
|
||||
|
||||
QObject::connect(reply, &QNetworkReply::finished, [=] {
|
||||
if (reply->error() == QNetworkReply::NetworkError::NoError) {
|
||||
QByteArray data = reply->readAll();
|
||||
QJsonDocument jsonDoc(QJsonDocument::fromJson(data));
|
||||
QJsonObject root = jsonDoc.object();
|
||||
|
||||
auto sets = root.value("sets").toObject();
|
||||
|
||||
for (const QJsonValue &set : sets) {
|
||||
auto emoticons = set.toObject().value("emoticons").toArray();
|
||||
|
||||
for (const QJsonValue &emote : emoticons) {
|
||||
QJsonObject object = emote.toObject();
|
||||
|
||||
// margins
|
||||
|
||||
int id = object.value("id").toInt();
|
||||
QString code = object.value("name").toString();
|
||||
|
||||
QJsonObject urls = object.value("urls").toObject();
|
||||
QString url1 = "http:" + urls.value("1").toString();
|
||||
|
||||
Emotes::getBttvEmotes().insert(
|
||||
code, new messages::LazyLoadedImage(
|
||||
url1, 1, code, code + "\nGlobal Ffz Emote"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
reply->deleteLater();
|
||||
manager->deleteLater();
|
||||
});
|
||||
}
|
||||
|
||||
void
|
||||
Channel::reloadFfzEmotes()
|
||||
{
|
||||
QNetworkAccessManager *manager = new QNetworkAccessManager();
|
||||
|
||||
QUrl url("https://api.frankerfacez.com/v1/set/global");
|
||||
QNetworkRequest request(url);
|
||||
|
||||
QNetworkReply *reply = manager->get(request);
|
||||
|
||||
QObject::connect(reply, &QNetworkReply::finished, [=] {
|
||||
if (reply->error() == QNetworkReply::NetworkError::NoError) {
|
||||
QByteArray data = reply->readAll();
|
||||
QJsonDocument jsonDoc(QJsonDocument::fromJson(data));
|
||||
QJsonObject root = jsonDoc.object();
|
||||
|
||||
auto sets = root.value("sets").toObject();
|
||||
|
||||
for (const QJsonValue &set : sets) {
|
||||
auto emoticons = set.toObject().value("emoticons").toArray();
|
||||
|
||||
for (const QJsonValue &emote : emoticons) {
|
||||
QJsonObject object = emote.toObject();
|
||||
|
||||
// margins
|
||||
|
||||
int id = object.value("id").toInt();
|
||||
QString code = object.value("name").toString();
|
||||
|
||||
QJsonObject urls = object.value("urls").toObject();
|
||||
QString url1 = "http:" + urls.value("1").toString();
|
||||
|
||||
Emotes::getBttvEmotes().insert(
|
||||
code, new messages::LazyLoadedImage(
|
||||
url1, 1, code, code + "\nGlobal Ffz Emote"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
reply->deleteLater();
|
||||
manager->deleteLater();
|
||||
});
|
||||
}
|
||||
|
||||
QVector<std::shared_ptr<messages::Message>>
|
||||
Channel::getMessagesClone()
|
||||
{
|
||||
|
|
10
channel.h
10
channel.h
|
@ -99,6 +99,13 @@ public:
|
|||
return messages;
|
||||
}
|
||||
|
||||
void
|
||||
reloadChannelEmotes()
|
||||
{
|
||||
reloadBttvEmotes();
|
||||
reloadFfzEmotes();
|
||||
}
|
||||
|
||||
private:
|
||||
QVector<std::shared_ptr<messages::Message>> messages;
|
||||
|
||||
|
@ -117,6 +124,9 @@ private:
|
|||
int streamViewerCount;
|
||||
QString streamStatus;
|
||||
QString streamGame;
|
||||
|
||||
void reloadBttvEmotes();
|
||||
void reloadFfzEmotes();
|
||||
};
|
||||
}
|
||||
|
||||
|
|
102
emotes.cpp
102
emotes.cpp
|
@ -2,6 +2,14 @@
|
|||
#include "resources.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonValue>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
#include <QNetworkRequest>
|
||||
#include <memory>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
|
@ -25,6 +33,100 @@ Emotes::Emotes()
|
|||
{
|
||||
}
|
||||
|
||||
void
|
||||
Emotes::loadGlobalEmotes()
|
||||
{
|
||||
loadBttvEmotes();
|
||||
loadFfzEmotes();
|
||||
}
|
||||
|
||||
void
|
||||
Emotes::loadBttvEmotes()
|
||||
{
|
||||
// bttv
|
||||
QNetworkAccessManager *manager = new QNetworkAccessManager();
|
||||
|
||||
QUrl url("https://api.betterttv.net/2/emotes");
|
||||
QNetworkRequest request(url);
|
||||
|
||||
QNetworkReply *reply = manager->get(request);
|
||||
|
||||
QObject::connect(reply, &QNetworkReply::finished, [=] {
|
||||
if (reply->error() == QNetworkReply::NetworkError::NoError) {
|
||||
QByteArray data = reply->readAll();
|
||||
QJsonDocument jsonDoc(QJsonDocument::fromJson(data));
|
||||
QJsonObject root = jsonDoc.object();
|
||||
|
||||
auto emotes = root.value("emotes").toArray();
|
||||
|
||||
QString _template = "https:" + root.value("urlTemplate").toString();
|
||||
|
||||
for (const QJsonValue &emote : emotes) {
|
||||
QString id = emote.toObject().value("id").toString();
|
||||
QString code = emote.toObject().value("code").toString();
|
||||
// emote.value("imageType").toString();
|
||||
|
||||
QString tmp = _template;
|
||||
tmp.detach();
|
||||
QString url =
|
||||
tmp.replace("{{id}}", id).replace("{{image}}", "1x");
|
||||
|
||||
Emotes::getBttvEmotes().insert(
|
||||
code, new messages::LazyLoadedImage(
|
||||
url, 1, code, code + "\nGlobal Bttv Emote"));
|
||||
}
|
||||
}
|
||||
|
||||
reply->deleteLater();
|
||||
manager->deleteLater();
|
||||
});
|
||||
}
|
||||
|
||||
void
|
||||
Emotes::loadFfzEmotes()
|
||||
{
|
||||
// bttv
|
||||
QNetworkAccessManager *manager = new QNetworkAccessManager();
|
||||
|
||||
QUrl url("https://api.frankerfacez.com/v1/set/global");
|
||||
QNetworkRequest request(url);
|
||||
|
||||
QNetworkReply *reply = manager->get(request);
|
||||
|
||||
QObject::connect(reply, &QNetworkReply::finished, [=] {
|
||||
if (reply->error() == QNetworkReply::NetworkError::NoError) {
|
||||
QByteArray data = reply->readAll();
|
||||
QJsonDocument jsonDoc(QJsonDocument::fromJson(data));
|
||||
QJsonObject root = jsonDoc.object();
|
||||
|
||||
auto sets = root.value("sets").toObject();
|
||||
|
||||
for (const QJsonValue &set : sets) {
|
||||
auto emoticons = set.toObject().value("emoticons").toArray();
|
||||
|
||||
for (const QJsonValue &emote : emoticons) {
|
||||
QJsonObject object = emote.toObject();
|
||||
|
||||
// margins
|
||||
|
||||
int id = object.value("id").toInt();
|
||||
QString code = object.value("name").toString();
|
||||
|
||||
QJsonObject urls = object.value("urls").toObject();
|
||||
QString url1 = "http:" + urls.value("1").toString();
|
||||
|
||||
Emotes::getBttvEmotes().insert(
|
||||
code, new messages::LazyLoadedImage(
|
||||
url1, 1, code, code + "\nGlobal Ffz Emote"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
reply->deleteLater();
|
||||
manager->deleteLater();
|
||||
});
|
||||
}
|
||||
|
||||
messages::LazyLoadedImage *
|
||||
Emotes::getTwitchEmoteById(const QString &name, long id)
|
||||
{
|
||||
|
|
3
emotes.h
3
emotes.h
|
@ -102,6 +102,9 @@ private:
|
|||
|
||||
static QString getTwitchEmoteLink(long id, qreal &scale);
|
||||
|
||||
static void loadFfzEmotes();
|
||||
static void loadBttvEmotes();
|
||||
|
||||
static int generation;
|
||||
};
|
||||
}
|
||||
|
|
2
main.cpp
2
main.cpp
|
@ -1,6 +1,7 @@
|
|||
#include "channels.h"
|
||||
#include "colorscheme.h"
|
||||
#include "emojis.h"
|
||||
#include "emotes.h"
|
||||
#include "ircmanager.h"
|
||||
#include "resources.h"
|
||||
#include "settings.h"
|
||||
|
@ -21,6 +22,7 @@ main(int argc, char *argv[])
|
|||
Settings::getInstance().load();
|
||||
Resources::load();
|
||||
Emojis::loadEmojis();
|
||||
Emotes::loadGlobalEmotes();
|
||||
|
||||
ColorScheme::getInstance().setColors(0, -0.8);
|
||||
|
||||
|
|
|
@ -66,7 +66,8 @@ LazyLoadedImage::loadImage()
|
|||
Emotes::incGeneration();
|
||||
Windows::layoutVisibleChatWidgets();
|
||||
|
||||
delete manager;
|
||||
reply->deleteLater();
|
||||
manager->deleteLater();
|
||||
});
|
||||
// }));
|
||||
}
|
||||
|
|
|
@ -11,15 +11,15 @@ class LazyLoadedImage
|
|||
{
|
||||
public:
|
||||
explicit LazyLoadedImage(const QString &url, qreal scale = 1,
|
||||
const QString &getName = "",
|
||||
const QString &getTooltip = "",
|
||||
const QMargins &getMargin = QMargins(),
|
||||
bool getIsHat = false);
|
||||
const QString &name = "",
|
||||
const QString &tooltip = "",
|
||||
const QMargins &margin = QMargins(),
|
||||
bool isHat = false);
|
||||
explicit LazyLoadedImage(QPixmap *pixmap, qreal scale = 1,
|
||||
const QString &getName = "",
|
||||
const QString &getTooltip = "",
|
||||
const QMargins &getMargin = QMargins(),
|
||||
bool getIsHat = false);
|
||||
const QString &name = "",
|
||||
const QString &tooltip = "",
|
||||
const QMargins &margin = QMargins(),
|
||||
bool isHat = false);
|
||||
|
||||
const QPixmap *
|
||||
getPixmap()
|
||||
|
|
Loading…
Reference in a new issue