diff options
| author | ilotterytea <iltsu@alright.party> | 2024-05-02 00:11:09 +0500 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2024-05-02 00:11:09 +0500 |
| commit | 0e20d75f3dcd12cc0c66c321684eadbed1513a9f (patch) | |
| tree | c5a2c511d6453fe493b667525d3ed625c03156d9 /src | |
| parent | 64ee8f8e7639c1e84a7e68d45e2aceec5299a4d6 (diff) | |
feat: method for getting chatter list
Diffstat (limited to 'src')
| -rw-r--r-- | src/api/twitch/helix_client.cpp | 27 | ||||
| -rw-r--r-- | src/api/twitch/helix_client.hpp | 3 |
2 files changed, 30 insertions, 0 deletions
diff --git a/src/api/twitch/helix_client.cpp b/src/api/twitch/helix_client.cpp index c5031f0..ceac720 100644 --- a/src/api/twitch/helix_client.cpp +++ b/src/api/twitch/helix_client.cpp @@ -75,4 +75,31 @@ namespace bot::api::twitch { return users; } + + std::vector<schemas::User> HelixClient::get_chatters( + const int &broadcaster_id, const int &moderator_id) const { + cpr::Response response = + cpr::Get(cpr::Url{this->base_url + "/chat/chatters?broadcaster_id=" + + std::to_string(broadcaster_id) + + "&moderator_id=" + std::to_string(moderator_id)}, + cpr::Bearer{this->token}, + cpr::Header{{"Client-Id", this->client_id.c_str()}}); + + if (response.status_code != 200) { + return {}; + } + + std::vector<schemas::User> users; + + nlohmann::json j = nlohmann::json::parse(response.text); + + for (const auto &d : j["data"]) { + schemas::User u{std::stoi(d["user_id"].get<std::string>()), + d["user_login"]}; + + users.push_back(u); + } + + return users; + } } diff --git a/src/api/twitch/helix_client.hpp b/src/api/twitch/helix_client.hpp index fedec7f..2b5f4ea 100644 --- a/src/api/twitch/helix_client.hpp +++ b/src/api/twitch/helix_client.hpp @@ -15,6 +15,9 @@ namespace bot::api::twitch { const std::vector<std::string> &logins) const; std::vector<schemas::User> get_users(const std::vector<int> &ids) const; + std::vector<schemas::User> get_chatters(const int &broadcaster_id, + const int &moderator_id) const; + private: std::vector<schemas::User> get_users_by_query( const std::string &query) const; |
