#pragma once #include #include #include #include #include #include "cpr/cpr.h" #include "emotespp/emotes.hpp" #include "ixwebsocket/IXWebSocket.h" namespace emotespp { class SevenTVWebsocketClient : public RetrieveEmoteWebsocket { public: SevenTVWebsocketClient(); void subscribe_emote_set(const std::string &emote_set_id); void unsubscribe_emote_set(const std::string &emote_set_id); void start(); private: Emote create_emote(const nlohmann::json &data); std::vector ids; ix::WebSocket websocket; bool is_connected = false; }; struct User { std::string alias_id, id, username, emote_set_id; }; struct EmoteSet { std::string id, name; User owner; std::vector emotes; }; class SevenTVAPIClient : public RetrieveEmoteAPI { public: SevenTVAPIClient() = default; ~SevenTVAPIClient() = default; std::vector get_channel_emotes( std::string &channel_id) const override { cpr::Response r = cpr::Get(cpr::Url{base_url + "/users/twitch/" + channel_id}); if (r.status_code != 200) { throw std::runtime_error( "Failed to get channel emotes. Status code: " + std::to_string(r.status_code)); } nlohmann::json j = nlohmann::json::parse(r.text); nlohmann::json set = j["emote_set"]; return this->parse_emoteset(set); } std::vector get_global_emotes() const override { cpr::Response r = cpr::Get(cpr::Url{base_url + "/emote-sets/global"}); if (r.status_code != 200) { throw std::runtime_error( "Failed to get global emotes. Status code: " + std::to_string(r.status_code)); } nlohmann::json j = nlohmann::json::parse(r.text); return this->parse_emoteset(j); } std::optional get_user_by_twitch_id( const unsigned int &twitch_id) const; std::optional get_user(const std::string &id) const; std::optional get_emote_set( const std::string &emote_set_id) const; private: std::vector parse_emoteset(const nlohmann::json &value) const; std::optional parse_user(const nlohmann::json &value) const; const std::string base_url = "https://7tv.io/v3"; }; }