code cleanup
This commit is contained in:
parent
62de22e02e
commit
be0be09a24
@ -9,7 +9,7 @@ private:
|
||||
WebSocket& web;
|
||||
NetworkManager& req;
|
||||
public:
|
||||
Author(const json& data) : data(data), web(WebSocket::getInstance()), req(NetworkManager::getInstance()) {}
|
||||
Author(const json& data) : data(data), web(WebSocket::getInstance()), req(NetworkManager::getInstance()) {};
|
||||
string content() {
|
||||
try {
|
||||
return data["d"]["content"];
|
||||
|
@ -8,8 +8,7 @@ private:
|
||||
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...>) {
|
||||
template<unsigned long... Is>void initializeNetsImpl(const json& data, std::index_sequence<Is...>) {
|
||||
net = std::make_tuple(std::make_unique<Args>(data)...);
|
||||
}
|
||||
json data;
|
||||
@ -18,6 +17,10 @@ public:
|
||||
Discord(const json& data) : data(data) {
|
||||
initializeNets(data);
|
||||
}
|
||||
template<unsigned long Index>
|
||||
auto& get() const {
|
||||
return *std::get<Index>(net);
|
||||
}
|
||||
};
|
||||
class Bot {
|
||||
private:
|
||||
|
@ -25,5 +25,8 @@ public:
|
||||
string deleteMessage(const string& channel_id, const string& message_id) {
|
||||
return req.request(HttpMethods::DELETE, DiscordEndpoints::details::latest + "/channels/" + channel_id + "/messages/" + message_id);
|
||||
}
|
||||
json pack(const json& pack) const {
|
||||
return { pack };
|
||||
}
|
||||
};
|
||||
#endif
|
@ -16,7 +16,7 @@ private:
|
||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
curl = curl_easy_init();
|
||||
if (!curl) {
|
||||
Log::create(ERROR, NETWORK, "Failed to initialize CURL");
|
||||
Log::create(CRITICAL, NETWORK, "Failed to initialize CURL");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
@ -84,23 +84,23 @@ struct HttpMethods {
|
||||
static constexpr const char* OPTIONS = "OPTIONS";
|
||||
};
|
||||
struct ApiVersion {
|
||||
static inline std::string api = "/api/";
|
||||
static inline std::string v10 = "v10";
|
||||
static inline std::string v9 = "v9";
|
||||
static inline std::string v8 = "v8";
|
||||
static inline std::string v7 = "v7";
|
||||
static inline std::string v6 = "v6";
|
||||
static inline std::string current = api + v6;
|
||||
static inline std::string latest = api + v10;
|
||||
static const inline std::string api = "/api/";
|
||||
static const inline std::string v10 = "v10";
|
||||
static const inline std::string v9 = "v9";
|
||||
static const inline std::string v8 = "v8";
|
||||
static const inline std::string v7 = "v7";
|
||||
static const inline std::string v6 = "v6";
|
||||
static const inline std::string current = api + v6;
|
||||
static const inline std::string latest = api + v10;
|
||||
};
|
||||
struct DiscordEndpoints {
|
||||
static inline std::string main_scheme = "https://";
|
||||
static inline std::string discord = main_scheme + "discord.com";
|
||||
static inline std::string images = main_scheme + "cdn.discord.com";
|
||||
static inline std::string media = main_scheme + "media.discord.com";
|
||||
static const inline std::string main_scheme = "https://";
|
||||
static const inline std::string discord = main_scheme + "discord.com";
|
||||
static const inline std::string images = main_scheme + "cdn.discord.com";
|
||||
static const inline std::string media = main_scheme + "media.discord.com";
|
||||
struct details {
|
||||
static inline std::string current = DiscordEndpoints::discord + ApiVersion::current;
|
||||
static inline std::string latest = DiscordEndpoints::discord + ApiVersion::latest;
|
||||
static const inline std::string current = DiscordEndpoints::discord + ApiVersion::current;
|
||||
static const inline std::string latest = DiscordEndpoints::discord + ApiVersion::latest;
|
||||
};
|
||||
};
|
||||
enum GatewayIntents {
|
||||
|
@ -14,21 +14,11 @@ public:
|
||||
#ifdef DEBUG
|
||||
std::string color;
|
||||
switch (lvl) {
|
||||
case INFO:
|
||||
color = "\033[34;1m";
|
||||
break;
|
||||
case WARNING:
|
||||
color = "\033[33;1m";
|
||||
break;
|
||||
case ERROR:
|
||||
color = "\033[31;1m";
|
||||
break;
|
||||
case CRITICAL:
|
||||
color = "\033[31;1;2m";
|
||||
break;
|
||||
default:
|
||||
color = "\033[0m";
|
||||
break;
|
||||
case INFO: color = "\033[34;1m"; break;
|
||||
case WARNING: color = "\033[33;1m"; break;
|
||||
case ERROR: color = "\033[31;1m"; break;
|
||||
case CRITICAL: color = "\033[31;1;2m"; break;
|
||||
default: color = "\033[0m"; break;
|
||||
}
|
||||
std::cout << color << "[" << getCurrentTime() << "][" << str(t) << "][" << str(lvl) << "] \033[0m" << message << "\033[0m" << std::endl;
|
||||
#endif
|
||||
|
@ -3,6 +3,5 @@
|
||||
#define j(...) {{__VA_ARGS__}}
|
||||
#define je(...) {__VA_ARGS__}
|
||||
#define g(x, y) (std::get<x>(y))
|
||||
#define ALL_INTENTS 131071
|
||||
#define DEBUG
|
||||
#define RELEASE
|
||||
#endif
|
@ -3,11 +3,11 @@
|
||||
int main(int argc, char* argv[]) {
|
||||
if (argc != 3) return -1;
|
||||
WebSocket* bot = &WebSocket::getInstance(argv[2], GatewayIntents::AllIntents);
|
||||
bot->on(GatewayEvents::READY, [](const Discord<Message, User>a) {
|
||||
bot->on(GatewayEvents::READY, [](const Discord<Message, User>&a) {
|
||||
cout << DiscordEndpoints::details::latest << endl;
|
||||
});
|
||||
bot->on(GatewayEvents::MESSAGE_CREATE, [](const Discord<Message, User, Author> msg) {
|
||||
g(0, msg.net)->send("939957962972229634", j("content", g(2, msg.net)->content()));
|
||||
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() }));
|
||||
});
|
||||
bot->start();
|
||||
return 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user