2020-10-04 18:32:52 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "common/NetworkRequest.hpp"
|
2021-07-11 11:12:49 +02:00
|
|
|
#include "providers/twitch/TwitchEmotes.hpp"
|
2020-10-04 18:32:52 +02:00
|
|
|
|
2022-12-31 15:41:01 +01:00
|
|
|
#include <QJsonArray>
|
|
|
|
#include <QJsonObject>
|
2021-05-08 15:57:00 +02:00
|
|
|
|
2020-10-04 18:32:52 +02:00
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
|
|
|
|
using IvrFailureCallback = std::function<void()>;
|
|
|
|
template <typename... T>
|
|
|
|
using ResultCallback = std::function<void(T...)>;
|
|
|
|
|
|
|
|
struct IvrSubage {
|
|
|
|
const bool isSubHidden;
|
|
|
|
const bool isSubbed;
|
|
|
|
const QString subTier;
|
|
|
|
const int totalSubMonths;
|
|
|
|
const QString followingSince;
|
|
|
|
|
2022-10-22 13:36:18 +02:00
|
|
|
IvrSubage(const QJsonObject &root)
|
|
|
|
: isSubHidden(root.value("statusHidden").toBool())
|
|
|
|
, isSubbed(!root.value("meta").isNull())
|
2020-10-04 18:32:52 +02:00
|
|
|
, subTier(root.value("meta").toObject().value("tier").toString())
|
|
|
|
, totalSubMonths(
|
|
|
|
root.value("cumulative").toObject().value("months").toInt())
|
|
|
|
, followingSince(root.value("followedAt").toString())
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-03-21 15:42:45 +01:00
|
|
|
struct IvrEmoteSet {
|
|
|
|
const QString setId;
|
|
|
|
const QString displayName;
|
|
|
|
const QString login;
|
2021-07-11 11:12:49 +02:00
|
|
|
const QString channelId;
|
2021-03-21 15:42:45 +01:00
|
|
|
const QString tier;
|
|
|
|
const QJsonArray emotes;
|
|
|
|
|
2022-10-22 13:36:18 +02:00
|
|
|
IvrEmoteSet(const QJsonObject &root)
|
2021-03-21 15:42:45 +01:00
|
|
|
: setId(root.value("setID").toString())
|
|
|
|
, displayName(root.value("channelName").toString())
|
|
|
|
, login(root.value("channelLogin").toString())
|
2021-07-11 11:12:49 +02:00
|
|
|
, channelId(root.value("channelID").toString())
|
2021-03-21 15:42:45 +01:00
|
|
|
, tier(root.value("tier").toString())
|
2021-07-11 11:12:49 +02:00
|
|
|
, emotes(root.value("emoteList").toArray())
|
2021-03-21 15:42:45 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct IvrEmote {
|
|
|
|
const QString code;
|
|
|
|
const QString id;
|
|
|
|
const QString setId;
|
|
|
|
const QString url;
|
2021-07-11 11:12:49 +02:00
|
|
|
const QString emoteType;
|
|
|
|
const QString imageType;
|
2021-03-21 15:42:45 +01:00
|
|
|
|
2022-10-22 13:36:18 +02:00
|
|
|
explicit IvrEmote(const QJsonObject &root)
|
2021-07-11 11:12:49 +02:00
|
|
|
: code(root.value("code").toString())
|
2021-03-21 15:42:45 +01:00
|
|
|
, id(root.value("id").toString())
|
|
|
|
, setId(root.value("setID").toString())
|
2021-07-11 11:12:49 +02:00
|
|
|
, url(QString(TWITCH_EMOTE_TEMPLATE)
|
|
|
|
.replace("{id}", this->id)
|
|
|
|
.replace("{scale}", "3.0"))
|
|
|
|
, emoteType(root.value("type").toString())
|
|
|
|
, imageType(root.value("assetType").toString())
|
2021-03-21 15:42:45 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-09-09 12:23:20 +02:00
|
|
|
class IvrApi final
|
2020-10-04 18:32:52 +02:00
|
|
|
{
|
|
|
|
public:
|
2022-10-22 13:36:18 +02:00
|
|
|
// https://api.ivr.fi/v2/docs/static/index.html#/Twitch/get_twitch_subage__user___channel_
|
2020-10-04 18:32:52 +02:00
|
|
|
void getSubage(QString userName, QString channelName,
|
|
|
|
ResultCallback<IvrSubage> resultCallback,
|
|
|
|
IvrFailureCallback failureCallback);
|
|
|
|
|
2021-07-17 17:18:17 +02:00
|
|
|
// https://api.ivr.fi/v2/docs/static/index.html#/Twitch/get_twitch_emotes_sets
|
2021-03-21 15:42:45 +01:00
|
|
|
void getBulkEmoteSets(QString emoteSetList,
|
|
|
|
ResultCallback<QJsonArray> successCallback,
|
2022-02-28 15:59:10 +01:00
|
|
|
IvrFailureCallback failureCallback);
|
2021-03-21 15:42:45 +01:00
|
|
|
|
2020-10-04 18:32:52 +02:00
|
|
|
static void initialize();
|
|
|
|
|
2023-09-09 12:23:20 +02:00
|
|
|
IvrApi() = default;
|
|
|
|
|
|
|
|
IvrApi(const IvrApi &) = delete;
|
|
|
|
IvrApi &operator=(const IvrApi &) = delete;
|
|
|
|
|
|
|
|
IvrApi(IvrApi &&) = delete;
|
|
|
|
IvrApi &operator=(IvrApi &&) = delete;
|
|
|
|
|
2020-10-04 18:32:52 +02:00
|
|
|
private:
|
|
|
|
NetworkRequest makeRequest(QString url, QUrlQuery urlQuery);
|
|
|
|
};
|
|
|
|
|
|
|
|
IvrApi *getIvr();
|
|
|
|
|
|
|
|
} // namespace chatterino
|