summaryrefslogtreecommitdiff
path: root/bot/src/api
diff options
context:
space:
mode:
Diffstat (limited to 'bot/src/api')
-rw-r--r--bot/src/api/twitch/helix_client.cpp32
-rw-r--r--bot/src/api/twitch/helix_client.hpp3
-rw-r--r--bot/src/api/twitch/schemas/stream.hpp7
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; }