Migrated cheermotes to Helix API (#2440)
Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
@@ -722,6 +722,45 @@ void Helix::manageAutoModMessages(
|
||||
.execute();
|
||||
}
|
||||
|
||||
void Helix::getCheermotes(
|
||||
QString broadcasterId,
|
||||
ResultCallback<std::vector<HelixCheermoteSet>> successCallback,
|
||||
HelixFailureCallback failureCallback)
|
||||
{
|
||||
QUrlQuery urlQuery;
|
||||
|
||||
urlQuery.addQueryItem("broadcaster_id", broadcasterId);
|
||||
|
||||
this->makeRequest("bits/cheermotes", urlQuery)
|
||||
.onSuccess([successCallback, failureCallback](auto result) -> Outcome {
|
||||
auto root = result.parseJson();
|
||||
auto data = root.value("data");
|
||||
|
||||
if (!data.isArray())
|
||||
{
|
||||
failureCallback();
|
||||
return Failure;
|
||||
}
|
||||
|
||||
std::vector<HelixCheermoteSet> cheermoteSets;
|
||||
|
||||
for (const auto &jsonStream : data.toArray())
|
||||
{
|
||||
cheermoteSets.emplace_back(jsonStream.toObject());
|
||||
}
|
||||
|
||||
successCallback(cheermoteSets);
|
||||
return Success;
|
||||
})
|
||||
.onError([broadcasterId, failureCallback](NetworkResult result) {
|
||||
qCDebug(chatterinoTwitch)
|
||||
<< "Failed to get cheermotes(broadcaster_id=" << broadcasterId
|
||||
<< "): " << result.status() << result.getData();
|
||||
failureCallback();
|
||||
})
|
||||
.execute();
|
||||
}
|
||||
|
||||
NetworkRequest Helix::makeRequest(QString url, QUrlQuery urlQuery)
|
||||
{
|
||||
assert(!url.startsWith("/"));
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/Aliases.hpp"
|
||||
#include "common/NetworkRequest.hpp"
|
||||
|
||||
#include <QJsonArray>
|
||||
@@ -193,6 +194,76 @@ struct HelixBlock {
|
||||
}
|
||||
};
|
||||
|
||||
struct HelixCheermoteImage {
|
||||
Url imageURL1x;
|
||||
Url imageURL2x;
|
||||
Url imageURL4x;
|
||||
|
||||
explicit HelixCheermoteImage(QJsonObject jsonObject)
|
||||
: imageURL1x(Url{jsonObject.value("1").toString()})
|
||||
, imageURL2x(Url{jsonObject.value("2").toString()})
|
||||
, imageURL4x(Url{jsonObject.value("4").toString()})
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
struct HelixCheermoteTier {
|
||||
QString id;
|
||||
QString color;
|
||||
int minBits;
|
||||
HelixCheermoteImage darkAnimated;
|
||||
HelixCheermoteImage darkStatic;
|
||||
HelixCheermoteImage lightAnimated;
|
||||
HelixCheermoteImage lightStatic;
|
||||
|
||||
explicit HelixCheermoteTier(QJsonObject jsonObject)
|
||||
: id(jsonObject.value("id").toString())
|
||||
, color(jsonObject.value("color").toString())
|
||||
, minBits(jsonObject.value("min_bits").toInt())
|
||||
, darkAnimated(jsonObject.value("images")
|
||||
.toObject()
|
||||
.value("dark")
|
||||
.toObject()
|
||||
.value("animated")
|
||||
.toObject())
|
||||
, darkStatic(jsonObject.value("images")
|
||||
.toObject()
|
||||
.value("dark")
|
||||
.toObject()
|
||||
.value("static")
|
||||
.toObject())
|
||||
, lightAnimated(jsonObject.value("images")
|
||||
.toObject()
|
||||
.value("light")
|
||||
.toObject()
|
||||
.value("animated")
|
||||
.toObject())
|
||||
, lightStatic(jsonObject.value("images")
|
||||
.toObject()
|
||||
.value("light")
|
||||
.toObject()
|
||||
.value("static")
|
||||
.toObject())
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
struct HelixCheermoteSet {
|
||||
QString prefix;
|
||||
QString type;
|
||||
std::vector<HelixCheermoteTier> tiers;
|
||||
|
||||
explicit HelixCheermoteSet(QJsonObject jsonObject)
|
||||
: prefix(jsonObject.value("prefix").toString())
|
||||
, type(jsonObject.value("type").toString())
|
||||
{
|
||||
for (const auto &tier : jsonObject.value("tiers").toArray())
|
||||
{
|
||||
this->tiers.emplace_back(tier.toObject());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
enum class HelixClipError {
|
||||
Unknown,
|
||||
ClipsDisabled,
|
||||
@@ -321,6 +392,12 @@ public:
|
||||
std::function<void()> successCallback,
|
||||
std::function<void(HelixAutoModMessageError)> failureCallback);
|
||||
|
||||
// https://dev.twitch.tv/docs/api/reference/#get-cheermotes
|
||||
void getCheermotes(
|
||||
QString broadcasterId,
|
||||
ResultCallback<std::vector<HelixCheermoteSet>> successCallback,
|
||||
HelixFailureCallback failureCallback);
|
||||
|
||||
void update(QString clientId, QString oauthToken);
|
||||
|
||||
static void initialize();
|
||||
|
||||
@@ -6,14 +6,6 @@ this folder describes what sort of API requests we do, what permissions are requ
|
||||
|
||||
We use few Kraken endpoints in Chatterino2.
|
||||
|
||||
### Get Cheermotes
|
||||
|
||||
URL: https://dev.twitch.tv/docs/v5/reference/bits#get-cheermotes
|
||||
|
||||
Migration path: **Not checked**
|
||||
|
||||
- We implement this API in `providers/twitch/TwitchChannel.cpp` to resolve a chats available cheer emotes. This helps us parse incoming messages like `pajaCheer1000`
|
||||
|
||||
### Get User Emotes
|
||||
|
||||
URL: https://dev.twitch.tv/docs/v5/reference/users#get-user-emotes
|
||||
@@ -88,16 +80,16 @@ Requires `clips:edit` scope
|
||||
|
||||
URL: https://dev.twitch.tv/docs/api/reference#get-channel-information
|
||||
|
||||
- We implement this in `providers/twitch/api/Helix.cpp getChannel`
|
||||
- We implement this in `providers/twitch/api/Helix.cpp getChannel`
|
||||
Used in:
|
||||
- `TwitchChannel` to refresh stream title
|
||||
|
||||
### Update Channel
|
||||
|
||||
URL: https://dev.twitch.tv/docs/api/reference#modify-channel-information
|
||||
URL: https://dev.twitch.tv/docs/api/reference#modify-channel-information
|
||||
Requires `channel:manage:broadcast` scope
|
||||
|
||||
- We implement this in `providers/twitch/api/Helix.cpp updateChannel`
|
||||
- We implement this in `providers/twitch/api/Helix.cpp updateChannel`
|
||||
Used in:
|
||||
- `/setgame` to update the game in the current channel
|
||||
- `/settitle` to update the title in the current channel
|
||||
@@ -113,29 +105,29 @@ Requires `user:edit:broadcast` scope
|
||||
|
||||
### Get User Block List
|
||||
|
||||
URL: https://dev.twitch.tv/docs/api/reference#get-user-block-list
|
||||
URL: https://dev.twitch.tv/docs/api/reference#get-user-block-list
|
||||
Requires `user:read:blocked_users` scope
|
||||
|
||||
- We implement this in `providers/twitch/api/Helix.cpp loadBlocks`
|
||||
- We implement this in `providers/twitch/api/Helix.cpp loadBlocks`
|
||||
Used in:
|
||||
- `providers/twitch/TwitchAccount.cpp loadBlocks` to load list of blocked (blocked) users by current user
|
||||
|
||||
### Block User
|
||||
|
||||
URL: https://dev.twitch.tv/docs/api/reference#block-user
|
||||
URL: https://dev.twitch.tv/docs/api/reference#block-user
|
||||
Requires `user:manage:blocked_users` scope
|
||||
|
||||
- We implement this in `providers/twitch/api/Helix.cpp blockUser`
|
||||
- We implement this in `providers/twitch/api/Helix.cpp blockUser`
|
||||
Used in:
|
||||
- `widgets/dialogs/UserInfoPopup.cpp` to block a user via checkbox in the usercard
|
||||
- `controllers/commands/CommandController.cpp` to block a user via "/block" command
|
||||
|
||||
### Unblock User
|
||||
|
||||
URL: https://dev.twitch.tv/docs/api/reference#unblock-user
|
||||
URL: https://dev.twitch.tv/docs/api/reference#unblock-user
|
||||
Requires `user:manage:blocked_users` scope
|
||||
|
||||
- We implement this in `providers/twitch/api/Helix.cpp unblockUser`
|
||||
- We implement this in `providers/twitch/api/Helix.cpp unblockUser`
|
||||
Used in:
|
||||
- `widgets/dialogs/UserInfoPopup.cpp` to unblock a user via checkbox in the usercard
|
||||
- `controllers/commands/CommandController.cpp` to unblock a user via "/unblock" command
|
||||
@@ -144,19 +136,27 @@ Requires `user:manage:blocked_users` scope
|
||||
|
||||
URL: https://dev.twitch.tv/docs/api/reference#search-categories
|
||||
|
||||
- We implement this in `providers/twitch/api/Helix.cpp searchGames`
|
||||
- We implement this in `providers/twitch/api/Helix.cpp searchGames`
|
||||
Used in:
|
||||
- `controllers/commands/CommandController.cpp` in `/setgame` command to fuzzy search for game titles
|
||||
|
||||
### Manage Held AutoMod Messages
|
||||
|
||||
URL: https://dev.twitch.tv/docs/api/reference#manage-held-automod-messages
|
||||
URL: https://dev.twitch.tv/docs/api/reference#manage-held-automod-messages
|
||||
Requires `moderator:manage:automod` scope
|
||||
|
||||
- We implement this in `providers/twitch/api/Helix.cpp manageAutoModMessages`
|
||||
- We implement this in `providers/twitch/api/Helix.cpp manageAutoModMessages`
|
||||
Used in:
|
||||
- `providers/twitch/TwitchAccount.cpp` to approve/deny held AutoMod messages
|
||||
|
||||
### Get Cheermotes
|
||||
|
||||
URL: https://dev.twitch.tv/docs/api/reference/#get-cheermotes
|
||||
|
||||
- We implement this in `providers/twitch/api/Helix.cpp getCheermotes`
|
||||
Used in:
|
||||
- `providers/twitch/TwitchChannel.cpp` to resolve a chats available cheer emotes. This helps us parse incoming messages like `pajaCheer1000`
|
||||
|
||||
## TMI
|
||||
|
||||
The TMI api is undocumented.
|
||||
|
||||
Reference in New Issue
Block a user