Better compliance with API reference
Send User-Agent header, move token auth to Authorization header. https://discordapp.com/developers/docs/reference
This commit is contained in:
parent
1f6d1a774d
commit
db3ab59daf
@ -4,15 +4,13 @@
|
||||
|
||||
#include "APIHelper.hpp"
|
||||
|
||||
extern std::string bot_token;
|
||||
|
||||
APIHelper::APIHelper() : BASE_URL("https://discordapp.com/api"), CHANNELS_URL(BASE_URL + "/channels"),
|
||||
TOKEN_PARAM("token=" + bot_token), JSON_CTYPE("application/json") {
|
||||
JSON_CTYPE("application/json") {
|
||||
http = new HTTPHelper();
|
||||
}
|
||||
|
||||
void APIHelper::send_message(std::string channel_id, std::string message) {
|
||||
const std::string url = CHANNELS_URL + "/" + channel_id + "/messages?" + TOKEN_PARAM;
|
||||
const std::string url = CHANNELS_URL + "/" + channel_id + "/messages";
|
||||
json data = {
|
||||
{ "content", message }
|
||||
};
|
||||
|
@ -18,8 +18,6 @@ public:
|
||||
private:
|
||||
const std::string BASE_URL;
|
||||
const std::string CHANNELS_URL;
|
||||
const std::string TOKEN;
|
||||
const std::string TOKEN_PARAM;
|
||||
const std::string JSON_CTYPE;
|
||||
|
||||
HTTPHelper *http;
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include "HTTPHelper.hpp"
|
||||
|
||||
extern std::string bot_token;
|
||||
|
||||
/*
|
||||
* Warning: (Awful) C Code
|
||||
*/
|
||||
@ -17,8 +19,15 @@ std::string HTTPHelper::post_request(std::string url, std::string content_type,
|
||||
// Now with real HTTPS!
|
||||
curl_easy_setopt(curl, CURLOPT_CAINFO, "bot/http/DiscordCA.crt");
|
||||
|
||||
std::string content_header = "Content-Type: " + content_type;
|
||||
headers = curl_slist_append(headers, content_header.c_str());
|
||||
std::string header_arr[3];
|
||||
header_arr[0] = "Content-Type: " + content_type;
|
||||
header_arr[1] = "Authorization: Bot " + bot_token;
|
||||
header_arr[2] = "User-Agent: DiscordBot(http://github.com/jackb-p/triviadiscord, 1.0)";
|
||||
|
||||
for (std::string h : header_arr) {
|
||||
headers = curl_slist_append(headers, h.c_str());
|
||||
}
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.c_str());
|
||||
|
Loading…
Reference in New Issue
Block a user