Purged kraken (#3578)

* Purged kraken code

* Remove kraken documentation

* Update Helix documentation

* Ran prettier

* Removed kraken files from qmake build file

* Remove now unnecessary .finally() callback
This commit is contained in:
Paweł
2022-02-28 14:59:10 +00:00
committed by GitHub
parent 6f7961444f
commit df70ca59e3
14 changed files with 57 additions and 329 deletions
-86
View File
@@ -1,86 +0,0 @@
#include "providers/twitch/api/Kraken.hpp"
#include "common/Outcome.hpp"
#include "common/QLogging.hpp"
#include "providers/twitch/TwitchCommon.hpp"
namespace chatterino {
static Kraken *instance = nullptr;
void Kraken::getUserEmotes(TwitchAccount *account,
ResultCallback<KrakenEmoteSets> successCallback,
KrakenFailureCallback failureCallback)
{
this->makeRequest(QString("users/%1/emotes").arg(account->getUserId()), {})
.authorizeTwitchV5(account->getOAuthClient(), account->getOAuthToken())
.onSuccess([successCallback](auto result) -> Outcome {
auto data = result.parseJson();
KrakenEmoteSets emoteSets(data);
successCallback(emoteSets);
return Success;
})
.onError([failureCallback](NetworkResult /*result*/) {
// TODO: make better xd
failureCallback();
})
.execute();
}
NetworkRequest Kraken::makeRequest(QString url, QUrlQuery urlQuery)
{
assert(!url.startsWith("/"));
if (this->clientId.isEmpty())
{
qCDebug(chatterinoTwitch)
<< "Kraken::makeRequest called without a client ID set BabyRage";
}
const QString baseUrl("https://api.twitch.tv/kraken/");
QUrl fullUrl(baseUrl + url);
fullUrl.setQuery(urlQuery);
if (!this->oauthToken.isEmpty())
{
return NetworkRequest(fullUrl)
.timeout(5 * 1000)
.header("Accept", "application/vnd.twitchtv.v5+json")
.header("Client-ID", this->clientId)
.header("Authorization", "OAuth " + this->oauthToken);
}
return NetworkRequest(fullUrl)
.timeout(5 * 1000)
.header("Accept", "application/vnd.twitchtv.v5+json")
.header("Client-ID", this->clientId);
}
void Kraken::update(QString clientId, QString oauthToken)
{
this->clientId = std::move(clientId);
this->oauthToken = std::move(oauthToken);
}
void Kraken::initialize()
{
assert(instance == nullptr);
instance = new Kraken();
getKraken()->update(getDefaultClientID(), "");
}
Kraken *getKraken()
{
assert(instance != nullptr);
return instance;
}
} // namespace chatterino
-59
View File
@@ -1,59 +0,0 @@
#pragma once
#include "common/NetworkRequest.hpp"
#include "providers/twitch/TwitchAccount.hpp"
#include <QString>
#include <QStringList>
#include <QUrlQuery>
#include <functional>
namespace chatterino {
using KrakenFailureCallback = std::function<void()>;
template <typename... T>
using ResultCallback = std::function<void(T...)>;
struct KrakenEmoteSets {
const QJsonObject emoteSets;
KrakenEmoteSets(QJsonObject jsonObject)
: emoteSets(jsonObject.value("emoticon_sets").toObject())
{
}
};
struct KrakenEmote {
const QString code;
const QString id;
KrakenEmote(QJsonObject jsonObject)
: code(jsonObject.value("code").toString())
, id(QString::number(jsonObject.value("id").toInt()))
{
}
};
class Kraken final : boost::noncopyable
{
public:
// https://dev.twitch.tv/docs/v5/reference/users#get-user-emotes
void getUserEmotes(TwitchAccount *account,
ResultCallback<KrakenEmoteSets> successCallback,
KrakenFailureCallback failureCallback);
void update(QString clientId, QString oauthToken);
static void initialize();
private:
NetworkRequest makeRequest(QString url, QUrlQuery urlQuery);
QString clientId;
QString oauthToken;
};
Kraken *getKraken();
} // namespace chatterino
+48 -64
View File
@@ -2,19 +2,6 @@
this folder describes what sort of API requests we do, what permissions are required for the requests etc
## Kraken (V5)
We use few Kraken endpoints in Chatterino2.
### Get User Emotes
URL: https://dev.twitch.tv/docs/v5/reference/users#get-user-emotes
Requires `user_subscriptions` scope
Migration path: **Unknown**
- We use this in `providers/twitch/TwitchAccount.cpp loadEmotes` to figure out which emotes a user is allowed to use!
## Helix
Full Helix API reference: https://dev.twitch.tv/docs/api/reference
@@ -23,134 +10,131 @@ Full Helix API reference: https://dev.twitch.tv/docs/api/reference
URL: https://dev.twitch.tv/docs/api/reference#get-users
- We implement this in `providers/twitch/api/Helix.cpp fetchUsers`.
Used in:
- `UserInfoPopup` to get ID, viewCount, displayName, createdAt of username we clicked
- `CommandController` to power any commands that need to get a user ID
- `Toasts` to get the profile picture of a streamer who just went live
- `TwitchAccount` block and unblock features to translate user name to user ID
Used in:
- `UserInfoPopup` to get ID, viewCount, displayName, createdAt of username we clicked
- `CommandController` to power any commands that need to get a user ID
- `Toasts` to get the profile picture of a streamer who just went live
- `TwitchAccount` block and unblock features to translate user name to user ID
### Get Users Follows
URL: https://dev.twitch.tv/docs/api/reference#get-users-follows
- We implement this in `providers/twitch/api/Helix.cpp fetchUsersFollows`
Used in:
- `UserInfoPopup` to get number of followers a user has
Used in:
- `UserInfoPopup` to get number of followers a user has
### Get Streams
URL: https://dev.twitch.tv/docs/api/reference#get-streams
- We implement this in `providers/twitch/api/Helix.cpp fetchStreams`
Used in:
- `TwitchChannel` to get live status, game, title, and viewer count of a channel
- `NotificationController` to provide notifications for channels you might not have open in Chatterino, but are still interested in getting notifications for
Used in:
- `TwitchChannel` to get live status, game, title, and viewer count of a channel
- `NotificationController` to provide notifications for channels you might not have open in Chatterino, but are still interested in getting notifications for
### Create Clip
URL: https://dev.twitch.tv/docs/api/reference#create-clip
Requires `clips:edit` scope
- We implement this in `providers/twitch/api/Helix.cpp createClip`
Used in:
- `TwitchChannel` to create a clip of a live broadcast
Used in:
- `TwitchChannel` to create a clip of a live broadcast
### Get Channel
URL: https://dev.twitch.tv/docs/api/reference#get-channel-information
- We implement this in `providers/twitch/api/Helix.cpp getChannel`
Used in:
- `TwitchChannel` to refresh stream title
Used in:
- `TwitchChannel` to refresh stream title
### Update Channel
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`
Used in:
- `/setgame` to update the game in the current channel
- `/settitle` to update the title in the current channel
Used in:
- `/setgame` to update the game in the current channel
- `/settitle` to update the title in the current channel
### Create Stream Marker
URL: https://dev.twitch.tv/docs/api/reference/#create-stream-marker
Requires `user:edit:broadcast` scope
- We implement this in `providers/twitch/api/Helix.cpp createStreamMarker`
Used in:
- `controllers/commands/CommandController.cpp` in /marker command
Used in:
- `controllers/commands/CommandController.cpp` in /marker command
### 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`
Used in:
- `providers/twitch/TwitchAccount.cpp loadBlocks` to load list of blocked (blocked) users by current user
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
Requires `user:manage:blocked_users` scope
- 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
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
Requires `user:manage:blocked_users` scope
- 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
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
### Search Categories
URL: https://dev.twitch.tv/docs/api/reference#search-categories
- 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
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
Requires `moderator:manage:automod` scope
- We implement this in `providers/twitch/api/Helix.cpp manageAutoModMessages`
Used in:
- `providers/twitch/TwitchAccount.cpp` to approve/deny held AutoMod messages
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`
Used in:
- `providers/twitch/TwitchChannel.cpp` to resolve a chats available cheer emotes. This helps us parse incoming messages like `pajaCheer1000`
### Get Emote Sets
URL: https://dev.twitch.tv/docs/api/reference#get-emote-sets
- We implement this in `providers/twitch/api/Helix.cpp getEmoteSetData`
Used in:
- `providers/twitch/TwitchAccount.cpp` to set emoteset owner data upon loading subscriber emotes from Kraken
Not used anywhere at the moment. Could be useful in the future for loading emotes from Helix.
### Get Channel Emotes
URL: https://dev.twitch.tv/docs/api/reference#get-channel-emotes
- We implement this in `providers/twitch/api/Helix.cpp getChannelEmotes`
Not used anywhere at the moment.
Not used anywhere at the moment.
## TMI