diff options
| author | ilotterytea <iltsu@alright.party> | 2025-04-17 21:05:17 +0500 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2025-04-17 21:05:17 +0500 |
| commit | b1a2e8a26cd08545ef93192b465b68c81bbc582b (patch) | |
| tree | 72650dedd7beabd298ea9a4fdc7c459d4df976ce | |
| parent | 83f9787b6e6327e4000cc2df1a98ea5a50a1e284 (diff) | |
feat: get channel information method
| -rw-r--r-- | bot/src/api/twitch/helix_client.cpp | 32 | ||||
| -rw-r--r-- | bot/src/api/twitch/helix_client.hpp | 3 | ||||
| -rw-r--r-- | bot/src/api/twitch/schemas/stream.hpp | 7 |
3 files changed, 42 insertions, 0 deletions
diff --git a/bot/src/api/twitch/helix_client.cpp b/bot/src/api/twitch/helix_client.cpp index b80895a..e3713d7 100644 --- a/bot/src/api/twitch/helix_client.cpp +++ b/bot/src/api/twitch/helix_client.cpp @@ -135,4 +135,36 @@ namespace bot::api::twitch { return streams; } + + std::vector<schemas::Stream> HelixClient::get_channel_information( + const std::vector<int> &ids) const { + std::vector<std::string> s; + + for (const int &id : ids) { + s.push_back("broadcaster_id=" + std::to_string(id)); + } + + cpr::Response response = + cpr::Get(cpr::Url{this->base_url + "/channels?" + + utils::string::join_vector(s, '&')}, + cpr::Bearer{this->token}, + cpr::Header{{"Client-Id", this->client_id.c_str()}}); + + if (response.status_code != 200) { + return {}; + } + + std::vector<schemas::Stream> streams; + + nlohmann::json j = nlohmann::json::parse(response.text); + + for (const auto &d : j["data"]) { + schemas::Stream u{std::stoi(d["broadcaster_id"].get<std::string>()), + d["broadcaster_login"], d["game_name"], d["title"]}; + + streams.push_back(u); + } + + return streams; + } } diff --git a/bot/src/api/twitch/helix_client.hpp b/bot/src/api/twitch/helix_client.hpp index 399b149..1207abf 100644 --- a/bot/src/api/twitch/helix_client.hpp +++ b/bot/src/api/twitch/helix_client.hpp @@ -25,6 +25,9 @@ namespace bot::api::twitch { std::vector<schemas::Stream> get_streams( const std::vector<int> &ids) const; + std::vector<schemas::Stream> get_channel_information( + const std::vector<int> &ids) const; + private: std::vector<schemas::User> get_users_by_query( const std::string &query) const; diff --git a/bot/src/api/twitch/schemas/stream.hpp b/bot/src/api/twitch/schemas/stream.hpp index e3d485e..69f4642 100644 --- a/bot/src/api/twitch/schemas/stream.hpp +++ b/bot/src/api/twitch/schemas/stream.hpp @@ -17,6 +17,13 @@ namespace bot::api::twitch::schemas { started_at(utils::chrono::string_to_time_point( started_at, "%Y-%m-%dT%H:%M:%SZ")) {} + Stream(int user_id, std::string user_login, std::string game_name, + std::string title) + : user_id(user_id), + user_login(user_login), + game_name(game_name), + title(title) {} + Stream(int user_id) : user_id(user_id) {} const int &get_user_id() const { return this->user_id; } |
