summaryrefslogtreecommitdiff
path: root/include/emotespp/seventv.hpp
diff options
context:
space:
mode:
authormoderndevslulw <moderndevslulw@alright.party>2025-04-04 14:30:36 +0500
committermoderndevslulw <moderndevslulw@alright.party>2025-04-04 14:30:36 +0500
commita44fc682a5f2eb54dfac6705ff21d0778639af6a (patch)
treea7b3d624bf89ed5b05a6890a00c40e22d9445b45 /include/emotespp/seventv.hpp
parentb19cee38da6bcdbaa8cd3a4115c0f24e7dadc9cd (diff)
feat: 7TV API client
Diffstat (limited to 'include/emotespp/seventv.hpp')
-rw-r--r--include/emotespp/seventv.hpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/include/emotespp/seventv.hpp b/include/emotespp/seventv.hpp
index cce8ae7..77db912 100644
--- a/include/emotespp/seventv.hpp
+++ b/include/emotespp/seventv.hpp
@@ -1,9 +1,12 @@
#pragma once
#include <nlohmann/json.hpp>
+#include <optional>
+#include <stdexcept>
#include <string>
#include <vector>
+#include "cpr/cpr.h"
#include "emotespp/emotes.hpp"
#include "ixwebsocket/IXWebSocket.h"
@@ -25,4 +28,63 @@ namespace emotespp {
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<Emote> emotes;
+ };
+
+ class SevenTVAPIClient : public RetrieveEmoteAPI<Emote> {
+ public:
+ SevenTVAPIClient() = default;
+ ~SevenTVAPIClient() = default;
+
+ std::vector<Emote> 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<Emote> 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<User> get_user_by_twitch_id(
+ const unsigned int &twitch_id) const;
+ std::optional<User> get_user(const std::string &id) const;
+ std::optional<EmoteSet> get_emote_set(
+ const std::string &emote_set_id) const;
+
+ private:
+ std::vector<Emote> parse_emoteset(const nlohmann::json &value) const;
+ std::optional<User> parse_user(const nlohmann::json &value) const;
+
+ const std::string base_url = "https://7tv.io/v3";
+ };
} \ No newline at end of file