From b1a2e8a26cd08545ef93192b465b68c81bbc582b Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Thu, 17 Apr 2025 21:05:17 +0500 Subject: feat: get channel information method --- bot/src/api/twitch/helix_client.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'bot/src/api/twitch/helix_client.cpp') 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 HelixClient::get_channel_information( + const std::vector &ids) const { + std::vector 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 streams; + + nlohmann::json j = nlohmann::json::parse(response.text); + + for (const auto &d : j["data"]) { + schemas::Stream u{std::stoi(d["broadcaster_id"].get()), + d["broadcaster_login"], d["game_name"], d["title"]}; + + streams.push_back(u); + } + + return streams; + } } -- cgit v1.2.3