fixes
This commit is contained in:
parent
be0be09a24
commit
1cbfe59bf6
@ -4,6 +4,7 @@
|
||||
#include <utils/json.hpp>
|
||||
#include <utils/log.hpp>
|
||||
#include <utils/enums.hpp>
|
||||
#include <utils/functions.hpp>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#endif
|
@ -9,8 +9,16 @@ private:
|
||||
WebSocket& web;
|
||||
NetworkManager& req;
|
||||
public:
|
||||
Author(const json& data) : data(data), web(WebSocket::getInstance()), req(NetworkManager::getInstance()) {};
|
||||
string content() {
|
||||
Author(const json& data) :
|
||||
data(data),
|
||||
web(WebSocket::getInstance()),
|
||||
req(NetworkManager::getInstance()),
|
||||
channel_id(functions::isNull(data["d"]["channel_id"])),
|
||||
global_name(functions::isNull(data["d"]["author"]["global_name"])),
|
||||
id(data["d"]["author"]["id"])
|
||||
{
|
||||
};
|
||||
string content() const {
|
||||
try {
|
||||
return data["d"]["content"];
|
||||
}
|
||||
@ -18,19 +26,11 @@ public:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
string channel_id() {
|
||||
return data["d"]["channel_id"];
|
||||
}
|
||||
string id() {
|
||||
return data["d"]["author"]["id"];
|
||||
}
|
||||
string global_name() {
|
||||
return data["d"]["author"]["global_name"].dump();
|
||||
}
|
||||
string discriminator() {
|
||||
const string channel_id, global_name, id;
|
||||
string discriminator() const {
|
||||
return data["d"]["author"]["discriminator"];
|
||||
}
|
||||
bool isBot() {
|
||||
bool isBot() const {
|
||||
try {
|
||||
return data["d"]["author"]["bot"];
|
||||
}
|
||||
|
@ -5,15 +5,15 @@ using std::string, std::cout, std::endl, nlohmann::json;
|
||||
template<typename...Args>
|
||||
class Discord {
|
||||
private:
|
||||
std::tuple<std::unique_ptr<Args>...> net;
|
||||
json data;
|
||||
void initializeNets(const json& data) {
|
||||
initializeNetsImpl(data, std::index_sequence_for<Args...>{});
|
||||
}
|
||||
template<unsigned long... Is>void initializeNetsImpl(const json& data, std::index_sequence<Is...>) {
|
||||
net = std::make_tuple(std::make_unique<Args>(data)...);
|
||||
}
|
||||
json data;
|
||||
public:
|
||||
std::tuple<std::unique_ptr<Args>...> net;
|
||||
Discord(const json& data) : data(data) {
|
||||
initializeNets(data);
|
||||
}
|
||||
@ -27,10 +27,10 @@ private:
|
||||
json data;
|
||||
public:
|
||||
Bot(const json& data) : data(data) {};
|
||||
string id() {
|
||||
string id() const {
|
||||
return data["d"]["id"];
|
||||
}
|
||||
bool isBot() {
|
||||
bool isBot() const {
|
||||
try {
|
||||
return data["d"]["bot"];
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ private:
|
||||
json data;
|
||||
public:
|
||||
Guild(const json& data) : data(data) {}
|
||||
string id() {
|
||||
string id() const {
|
||||
return data["d"]["user"]["id"];
|
||||
}
|
||||
};
|
||||
|
@ -28,7 +28,7 @@ public:
|
||||
virtual string me() {
|
||||
return req.request(HttpMethods::GET, DiscordEndpoints::details::latest + "/users/@me");
|
||||
}
|
||||
bool isBot() {
|
||||
bool isBot() const {
|
||||
try {
|
||||
return data["d"]["author"]["bot"];
|
||||
}
|
||||
|
13
libs/utils/functions.hpp
Normal file
13
libs/utils/functions.hpp
Normal file
@ -0,0 +1,13 @@
|
||||
#ifndef UTILS_FUNCTIONS_HPP_
|
||||
#define UTILS_FUNCTIONS_HPP_
|
||||
struct functions {
|
||||
static inline std::string isNull(const nlohmann::json& str) {
|
||||
try {
|
||||
return str.is_null() ? str.dump() : str.get<std::string>();
|
||||
}
|
||||
catch (...) {
|
||||
return "null";
|
||||
}
|
||||
}
|
||||
};
|
||||
#endif
|
@ -1,7 +1,4 @@
|
||||
#ifndef UTILS_TYPES_HPP_
|
||||
#define UTILS_TYPES_HPP_
|
||||
#define j(...) {{__VA_ARGS__}}
|
||||
#define je(...) {__VA_ARGS__}
|
||||
#define g(x, y) (std::get<x>(y))
|
||||
#define RELEASE
|
||||
#endif
|
@ -7,7 +7,7 @@ int main(int argc, char* argv[]) {
|
||||
cout << DiscordEndpoints::details::latest << endl;
|
||||
});
|
||||
bot->on(GatewayEvents::MESSAGE_CREATE, [bot](const Discord<Message, User, Author>& msg) {
|
||||
msg.get<0>().send("939957962972229634", msg.get<0>().pack({ "content", msg.get<2>().content() }));
|
||||
msg.get<0>().send("939957962972229634", msg.get<0>().pack({ "content", msg.get<2>().id }));
|
||||
});
|
||||
bot->start();
|
||||
return 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user