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