summaryrefslogtreecommitdiff
path: root/discord
diff options
context:
space:
mode:
authorouwou <26526779+ouwou@users.noreply.github.com>2020-11-27 01:37:01 -0500
committerouwou <26526779+ouwou@users.noreply.github.com>2020-11-27 01:37:01 -0500
commitae77bfd1d1df50d8159e50fee4f7c5616cffe1b8 (patch)
tree4c1ac7be700ea46432ede85a0d128394e3b31b45 /discord
parent1463d8da9e1b4c49021e6fa75795e2cd054b6227 (diff)
downloadabaddon-portaudio-ae77bfd1d1df50d8159e50fee4f7c5616cffe1b8.tar.gz
abaddon-portaudio-ae77bfd1d1df50d8159e50fee4f7c5616cffe1b8.zip
set user-agent through ini
Diffstat (limited to 'discord')
-rw-r--r--discord/discord.cpp5
-rw-r--r--discord/discord.hpp1
-rw-r--r--discord/http.cpp35
-rw-r--r--discord/http.hpp2
-rw-r--r--discord/websocket.cpp5
-rw-r--r--discord/websocket.hpp3
6 files changed, 41 insertions, 10 deletions
diff --git a/discord/discord.cpp b/discord/discord.cpp
index 3e31b13..30b0345 100644
--- a/discord/discord.cpp
+++ b/discord/discord.cpp
@@ -421,6 +421,11 @@ void DiscordClient::UpdateToken(std::string token) {
}
}
+void DiscordClient::SetUserAgent(std::string agent) {
+ m_http.SetUserAgent(agent);
+ m_websocket.SetUserAgent(agent);
+}
+
void DiscordClient::HandleGatewayMessageRaw(std::string str) {
// handles multiple zlib compressed messages, calling HandleGatewayMessage when a full message is received
std::vector<uint8_t> buf(str.begin(), str.end());
diff --git a/discord/discord.hpp b/discord/discord.hpp
index a8729d8..487903f 100644
--- a/discord/discord.hpp
+++ b/discord/discord.hpp
@@ -112,6 +112,7 @@ public:
std::optional<Snowflake> FindDM(Snowflake user_id); // wont find group dms
void UpdateToken(std::string token);
+ void SetUserAgent(std::string agent);
private:
static const constexpr int InflateChunkSize = 0x10000;
diff --git a/discord/http.cpp b/discord/http.cpp
index 41f6c17..a435aef 100644
--- a/discord/http.cpp
+++ b/discord/http.cpp
@@ -6,6 +6,10 @@ HTTPClient::HTTPClient(std::string api_base)
m_dispatcher.connect(sigc::mem_fun(*this, &HTTPClient::RunCallbacks));
}
+void HTTPClient::SetUserAgent(std::string agent) {
+ m_agent = agent;
+}
+
void HTTPClient::SetAuth(std::string auth) {
m_authorization = auth;
}
@@ -16,16 +20,18 @@ void HTTPClient::MakeDELETE(std::string path, std::function<void(cpr::Response r
auto headers = cpr::Header {
{ "Authorization", m_authorization },
};
+ auto ua = cpr::UserAgent {m_agent != "" ? m_agent : "Abaddon" };
+
#ifdef USE_LOCAL_PROXY
m_futures.push_back(cpr::DeleteCallback(
std::bind(&HTTPClient::OnResponse, this, std::placeholders::_1, cb),
- url, headers,
+ url, headers, ua,
cpr::Proxies { { "http", "127.0.0.1:8888" }, { "https", "127.0.0.1:8888" } },
cpr::VerifySsl { false }));
#else
m_futures.push_back(cpr::DeleteCallback(
std::bind(&HTTPClient::OnResponse, this, std::placeholders::_1, cb),
- url, headers));
+ url, headers, ua));
#endif
}
@@ -36,17 +42,19 @@ void HTTPClient::MakePATCH(std::string path, std::string payload, std::function<
{ "Authorization", m_authorization },
{ "Content-Type", "application/json" },
};
+ auto ua = cpr::UserAgent { m_agent != "" ? m_agent : "Abaddon" };
+
auto body = cpr::Body { payload };
#ifdef USE_LOCAL_PROXY
m_futures.push_back(cpr::PatchCallback(
std::bind(&HTTPClient::OnResponse, this, std::placeholders::_1, cb),
- url, headers, body,
+ url, headers, body, ua,
cpr::Proxies { { "http", "127.0.0.1:8888" }, { "https", "127.0.0.1:8888" } },
cpr::VerifySsl { false }));
#else
m_futures.push_back(cpr::PatchCallback(
std::bind(&HTTPClient::OnResponse, this, std::placeholders::_1, cb),
- url, headers, body));
+ url, headers, body, ua));
#endif
}
@@ -57,17 +65,19 @@ void HTTPClient::MakePOST(std::string path, std::string payload, std::function<v
{ "Authorization", m_authorization },
{ "Content-Type", "application/json" },
};
+ auto ua = cpr::UserAgent { m_agent != "" ? m_agent : "Abaddon" };
+
auto body = cpr::Body { payload };
#ifdef USE_LOCAL_PROXY
m_futures.push_back(cpr::PostCallback(
std::bind(&HTTPClient::OnResponse, this, std::placeholders::_1, cb),
- url, headers, body,
+ url, headers, body, ua,
cpr::Proxies { { "http", "127.0.0.1:8888" }, { "https", "127.0.0.1:8888" } },
cpr::VerifySsl { false }));
#else
m_futures.push_back(cpr::PostCallback(
std::bind(&HTTPClient::OnResponse, this, std::placeholders::_1, cb),
- url, headers, body));
+ url, headers, body, ua));
#endif
}
@@ -78,17 +88,19 @@ void HTTPClient::MakePUT(std::string path, std::string payload, std::function<vo
{ "Authorization", m_authorization },
{ "Content-Type", "application/json" },
};
+ auto ua = cpr::UserAgent { m_agent != "" ? m_agent : "Abaddon" };
+
auto body = cpr::Body { payload };
#ifdef USE_LOCAL_PROXY
m_futures.push_back(cpr::PutCallback(
std::bind(&HTTPClient::OnResponse, this, std::placeholders::_1, cb),
- url, headers, body,
+ url, headers, body, ua,
cpr::Proxies { { "http", "127.0.0.1:8888" }, { "https", "127.0.0.1:8888" } },
cpr::VerifySsl { false }));
#else
m_futures.push_back(cpr::PutCallback(
std::bind(&HTTPClient::OnResponse, this, std::placeholders::_1, cb),
- url, headers, body));
+ url, headers, body, ua));
#endif
}
@@ -99,16 +111,19 @@ void HTTPClient::MakeGET(std::string path, std::function<void(cpr::Response r)>
{ "Authorization", m_authorization },
{ "Content-Type", "application/json" },
};
+ auto ua = cpr::UserAgent { m_agent != "" ? m_agent : "Abaddon" };
+
+ auto x = cpr::UserAgent {};
#ifdef USE_LOCAL_PROXY
m_futures.push_back(cpr::GetCallback(
std::bind(&HTTPClient::OnResponse, this, std::placeholders::_1, cb),
- url, headers,
+ url, headers, ua,
cpr::Proxies { { "http", "127.0.0.1:8888" }, { "https", "127.0.0.1:8888" } },
cpr::VerifySsl { false }));
#else
m_futures.push_back(cpr::GetCallback(
std::bind(&HTTPClient::OnResponse, this, std::placeholders::_1, cb),
- url, headers));
+ url, headers, ua));
#endif
}
diff --git a/discord/http.hpp b/discord/http.hpp
index db60498..b664c86 100644
--- a/discord/http.hpp
+++ b/discord/http.hpp
@@ -13,6 +13,7 @@ class HTTPClient {
public:
HTTPClient(std::string api_base);
+ void SetUserAgent(std::string agent);
void SetAuth(std::string auth);
void MakeDELETE(std::string path, std::function<void(cpr::Response r)> cb);
void MakeGET(std::string path, std::function<void(cpr::Response r)> cb);
@@ -32,4 +33,5 @@ private:
std::vector<std::future<void>> m_futures;
std::string m_api_base;
std::string m_authorization;
+ std::string m_agent;
};
diff --git a/discord/websocket.cpp b/discord/websocket.cpp
index 2dc4ad0..5cd82b1 100644
--- a/discord/websocket.cpp
+++ b/discord/websocket.cpp
@@ -7,9 +7,14 @@ void Websocket::StartConnection(std::string url) {
m_websocket.disableAutomaticReconnection();
m_websocket.setUrl(url);
m_websocket.setOnMessageCallback(std::bind(&Websocket::OnMessage, this, std::placeholders::_1));
+ m_websocket.setExtraHeaders(ix::WebSocketHttpHeaders { { "User-Agent", m_agent } }); // idk if this actually works
m_websocket.start();
}
+void Websocket::SetUserAgent(std::string agent) {
+ m_agent = agent;
+}
+
void Websocket::Stop() {
m_websocket.stop();
}
diff --git a/discord/websocket.hpp b/discord/websocket.hpp
index ed6317a..e6a6489 100644
--- a/discord/websocket.hpp
+++ b/discord/websocket.hpp
@@ -11,6 +11,8 @@ public:
Websocket();
void StartConnection(std::string url);
+ void SetUserAgent(std::string agent);
+
void Send(const std::string &str);
void Send(const nlohmann::json &j);
void Stop();
@@ -21,6 +23,7 @@ private:
void OnMessage(const ix::WebSocketMessagePtr &msg);
ix::WebSocket m_websocket;
+ std::string m_agent;
public:
typedef sigc::signal<void> type_signal_open;