fixes
This commit is contained in:
parent
9542885b42
commit
f5341d6ea5
@ -18,8 +18,6 @@ find_package(CURL REQUIRED)
|
||||
find_path(IXWEBSOCKET_INCLUDE_DIR ixwebsocket)
|
||||
find_library(IXWEBSOCKET_LIBRARIES ixwebsocket)
|
||||
|
||||
message(STATUS "Current compiler: ${CMAKE_CXX_COMPILER}")
|
||||
|
||||
if(NOT IXWEBSOCKET_INCLUDE_DIR OR NOT IXWEBSOCKET_LIBRARIES)
|
||||
message(FATAL_ERROR "ixwebsocket not found")
|
||||
endif()
|
||||
@ -42,6 +40,7 @@ if(CMAKE_BUILD_TYPE)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
message(STATUS "Current compiler: ${CMAKE_CXX_COMPILER}")
|
||||
message(STATUS "${CMAKE_BUILD_TYPE}")
|
||||
|
||||
add_executable(${PROJECT_NAME} ${SOURCE})
|
||||
|
@ -4,8 +4,7 @@
|
||||
#include <net.hpp>
|
||||
class Author {
|
||||
private:
|
||||
nlohmann::json data;
|
||||
const nlohmann::json& d;
|
||||
const nlohmann::json& data, &d;
|
||||
WebSocket& web;
|
||||
NetworkManager& req;
|
||||
public:
|
||||
|
@ -4,16 +4,10 @@
|
||||
template<typename...Args>
|
||||
class Discord {
|
||||
private:
|
||||
const nlohmann::json& data;
|
||||
std::tuple<std::unique_ptr<Args>...> net;
|
||||
nlohmann::json data;
|
||||
template<unsigned long... Is>
|
||||
void initializeCtx(const nlohmann::json& data, std::index_sequence<Is...>) {
|
||||
net = std::make_tuple(std::make_unique<Args>(data)...);
|
||||
}
|
||||
public:
|
||||
Discord(const nlohmann::json& data) : data(data) {
|
||||
initializeCtx(data, std::index_sequence_for<Args...>{});
|
||||
}
|
||||
Discord(const nlohmann::json& data) : data(data), net(std::make_tuple(std::make_unique<Args>(data)...)) {}
|
||||
template<class T>
|
||||
[[deprecated("Use ctx() instead")]] auto& get() const {
|
||||
return *std::get<std::unique_ptr<T>>(net);
|
||||
@ -24,7 +18,7 @@ public:
|
||||
};
|
||||
class Bot {
|
||||
private:
|
||||
nlohmann::json data;
|
||||
const nlohmann::json& data;
|
||||
public:
|
||||
Bot(const nlohmann::json& data) : data(data) {};
|
||||
std::string id() const {
|
||||
|
@ -4,11 +4,11 @@
|
||||
#include <net.hpp>
|
||||
class Channel {
|
||||
private:
|
||||
nlohmann::json data;
|
||||
const nlohmann::json& data;
|
||||
WebSocket& web;
|
||||
NetworkManager& req;
|
||||
public:
|
||||
Channel(const nlohmann::json& data = "") : data(data), web(WebSocket::getInstance()), req(NetworkManager::getInstance()) {}
|
||||
Channel(const nlohmann::json& data) : data(data), web(WebSocket::getInstance()), req(NetworkManager::getInstance()) {}
|
||||
std::string send(const nlohmann::json& msg) {
|
||||
return req.request(HttpMethods::POST, DiscordEndpoints::details::latest + "/channels/" + data["d"]["channel_id"].get<std::string>() + "/messages", msg.dump());
|
||||
}
|
||||
|
@ -4,11 +4,11 @@
|
||||
#include <net.hpp>
|
||||
class Message {
|
||||
private:
|
||||
nlohmann::json data;
|
||||
const nlohmann::json& data;
|
||||
WebSocket& web;
|
||||
NetworkManager& req;
|
||||
public:
|
||||
Message(const nlohmann::json& data = "") : data(data), web(WebSocket::getInstance()), req(NetworkManager::getInstance()) {};
|
||||
Message(const nlohmann::json& data) : data(data), web(WebSocket::getInstance()), req(NetworkManager::getInstance()) {};
|
||||
std::string send(const std::string& id, const nlohmann::json& msg) {
|
||||
return req.request(HttpMethods::POST, DiscordEndpoints::details::latest + "/channels/" + id + "/messages", msg.dump());
|
||||
}
|
||||
@ -27,9 +27,9 @@ public:
|
||||
return { { key, value } };
|
||||
}
|
||||
struct Api {
|
||||
nlohmann::json data;
|
||||
const nlohmann::json& data;
|
||||
NetworkManager& req;
|
||||
Api(const nlohmann::json& json = "") : data(json), req(NetworkManager::getInstance()) {};
|
||||
Api(const nlohmann::json& json) : data(json), req(NetworkManager::getInstance()) {};
|
||||
unsigned latency() const {
|
||||
return req.getLatency();
|
||||
}
|
||||
|
@ -5,13 +5,12 @@
|
||||
#include <vector>
|
||||
class User {
|
||||
private:
|
||||
nlohmann::json data;
|
||||
const nlohmann::json& data;
|
||||
WebSocket& web;
|
||||
NetworkManager& req;
|
||||
public:
|
||||
User(const nlohmann::json& data = "") : data(data), web(WebSocket::getInstance()), req(NetworkManager::getInstance()),
|
||||
isBot(data["d"]["user"].contains("bot") ? data["d"]["user"]["bot"].get<bool>() : false) {
|
||||
}
|
||||
isBot(data["d"]["user"].contains("bot") ? data["d"]["user"]["bot"].get<bool>() : false) {}
|
||||
bool isBot;
|
||||
/*
|
||||
nlohmann::json extract(const std::vector<std::string>& keys) {
|
||||
|
@ -16,6 +16,16 @@ protected:
|
||||
}
|
||||
}
|
||||
public:
|
||||
void getEvents() {
|
||||
Log::create(CRITICAL, WEBSOCKET, "Event list");
|
||||
for (const auto& handler : handlers) {
|
||||
Log::create(INFO, WEBSOCKET, handler.first);
|
||||
}
|
||||
Log::create(CRITICAL, WEBSOCKET, "End of list");
|
||||
}
|
||||
void start() {
|
||||
while (1) std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
}
|
||||
void on(const std::string& event, eventHandlers handler) {
|
||||
handlers[event].emplace_back(handler);
|
||||
}
|
||||
@ -139,8 +149,5 @@ public:
|
||||
int getIntents() const {
|
||||
return WebSocket::intents;
|
||||
}
|
||||
void start() {
|
||||
while (1) std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
}
|
||||
};
|
||||
#endif
|
@ -34,13 +34,13 @@ int main(int argc, char* argv[]) {
|
||||
std::cout << nlohmann::json::parse(user->me())["username"].get<std::string>() << std::endl;
|
||||
});
|
||||
|
||||
bot->on(GatewayEvents::MESSAGE_CREATE, [](const Discord<Message, User, Author>& msg) {
|
||||
auto& [message, user, author] = msg.ctx();
|
||||
bot->on(GatewayEvents::MESSAGE_CREATE, [bot](const Discord<Message, Author>& msg) {
|
||||
auto& [message, author] = msg.ctx();
|
||||
if (!author->isBot) {
|
||||
message->send("939957962972229634", message->pack("content", author->content));
|
||||
bot->getEvents();
|
||||
}
|
||||
});
|
||||
|
||||
bot->start();
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user