Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wtg dev #11

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions .travis.xml

This file was deleted.

52 changes: 50 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,54 @@
"utility": "cpp",
"xmemory0": "cpp",
"xtr1common": "cpp",
"xutility": "cpp"
}
"xutility": "cpp",
"xstring": "cpp",
"algorithm": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"exception": "cpp",
"forward_list": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"ios": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"iterator": "cpp",
"limits": "cpp",
"list": "cpp",
"map": "cpp",
"new": "cpp",
"numeric": "cpp",
"ostream": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"string": "cpp",
"system_error": "cpp",
"typeinfo": "cpp",
"unordered_map": "cpp",
"valarray": "cpp",
"vector": "cpp",
"xfacet": "cpp",
"xfunctional": "cpp",
"xhash": "cpp",
"xiosbase": "cpp",
"xlocale": "cpp",
"xlocinfo": "cpp",
"xlocmon": "cpp",
"xlocnum": "cpp",
"xloctime": "cpp",
"xmemory": "cpp",
"xstddef": "cpp",
"xtree": "cpp"
},
"editor.tabSize": 4
}
12 changes: 11 additions & 1 deletion include/dpp/discord_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,19 @@

using namespace std;

class RichEmbed {
public:
string title;
string description;
string url;
int color;
};

class DiscordClient {
public:
bool login(string type, string token);
bool SendMessage(string channel, string content);
bool SendEmbed(string channel, RichEmbed embed);
private:
dpp::discord_http _dh;
};
};
20 changes: 10 additions & 10 deletions include/dpp/discord_http.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
// This is mostly to be used in the future base_client class

namespace dpp {
class discord_http {
private:
urler m_u;
public:
discord_http();
void add_token(std::string t_type, std::string t_token);
nlohmann::json post(std::string t_endpoint, nlohmann::json t_payload);
nlohmann::json get(std::string t_endpoint, std::string t_url_encoded);
// Other methods are to be added
};
class discord_http {
private:
urler m_u;
public:
discord_http();
void add_token(std::string t_type, std::string t_token);
nlohmann::json post(std::string t_endpoint, nlohmann::json t_payload);
nlohmann::json get(std::string t_endpoint, std::string t_url_encoded);
// Other methods are to be added
};
}
8 changes: 4 additions & 4 deletions include/dpp/http_res.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#include <string>

namespace dpp {
struct http_res {
std::string body;
std::string base;
};
struct http_res {
std::string body;
std::string base;
};
}
36 changes: 18 additions & 18 deletions include/dpp/urler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@
using json = nlohmann::json;

namespace dpp {
class urler {
private:
std::string m_method;
unsigned int m_http_ver;
std::string m_path;
std::string m_body;
json m_headers;

public:
urler();
void set_method(std::string t_method);
void set_http_ver(unsigned int t_http_ver);
void set_path(std::string t_path);
void set_body(std::string t_body);
void set_header(std::string t_header, std::string t_value);
void delete_header(std::string t_header);
http_res perform(std::string t_url);
};
class urler {
private:
std::string m_method;
unsigned int m_http_ver;
std::string m_path;
std::string m_body;
json m_headers;
public:
urler();
void set_method(std::string t_method);
void set_http_ver(unsigned int t_http_ver);
void set_path(std::string t_path);
void set_body(std::string t_body);
void set_header(std::string t_header, std::string t_value);
void delete_header(std::string t_header);
http_res perform(std::string t_url);
};
}
4 changes: 0 additions & 4 deletions src/comp.sh

This file was deleted.

22 changes: 22 additions & 0 deletions src/libs/discord_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,26 @@ bool DiscordClient::login(string type, string token) {
return false;
}
_dh.add_token(type, token);
return true;
}

bool DiscordClient::SendMessage(string channel, string content) {
nlohmann::json message;
message["content"] = content;
nlohmann::json response = _dh.post("/channels/" + channel + "/messages", message);
cout << response.dump();
}

bool DiscordClient::SendEmbed(string channel, RichEmbed embed) {
nlohmann::json rembed;
rembed["title"] = embed.title;
rembed["description"] = embed.title;
rembed["url"] = embed.title;
rembed["title"] = embed.title;
rembed["type"] = "rich";
nlohmann::json message;
message["embed"] = rembed.dump();
nlohmann::json response = _dh.post("/channels/" + channel + "/messages", message);
cout << "response:" << endl;
cout << response.dump();
}
34 changes: 17 additions & 17 deletions src/libs/discord_http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,31 @@ const std::string discord_url = "discordapp.com";
const std::string discord_api_prefix = "/api";

dpp::discord_http::discord_http() {
m_u.set_http_ver(11);
m_u.set_method("GET");
m_u.set_header("Host", discord_url);
m_u.set_header("User-Agent", "DiscordBot");
m_u.set_http_ver(11);
m_u.set_method("GET");
m_u.set_header("Host", discord_url);
m_u.set_header("User-Agent", "DiscordBot");
}

nlohmann::json dpp::discord_http::post(std::string t_endpoint, nlohmann::json t_payload) {
m_u.set_method("POST");
m_u.set_path(discord_api_prefix + t_endpoint);
m_u.set_body(t_payload.dump());
m_u.set_header("Content-Type", "application/json");
std::string res = m_u.perform(discord_url).body;
return nlohmann::json::parse(res);
m_u.set_method("POST");
m_u.set_path(discord_api_prefix + t_endpoint);
m_u.set_body(t_payload.dump());
m_u.set_header("Content-Type", "application/json");
std::string res = m_u.perform(discord_url).body;
return nlohmann::json::parse(res);
}

nlohmann::json dpp::discord_http::get(std::string t_endpoint, std::string t_url_encoded) {
m_u.set_method("GET");
m_u.set_path(discord_api_prefix + t_endpoint);
m_u.set_body(t_url_encoded);
m_u.set_header("Content-Type", "application/x-www-form-urlencoded");
std::string res = m_u.perform(discord_url).body;
return nlohmann::json::parse(res);
m_u.set_method("GET");
m_u.set_path(discord_api_prefix + t_endpoint);
m_u.set_body(t_url_encoded);
m_u.set_header("Content-Type", "application/x-www-form-urlencoded");
std::string res = m_u.perform(discord_url).body;
return nlohmann::json::parse(res);
}

// The next method will be for the Base Client when he logs
void dpp::discord_http::add_token(std::string t_type, std::string t_token) {
m_u.set_header("Authorization", t_type + " " + t_token);
m_u.set_header("Authorization", t_type + " " + t_token);
}
Loading