forked from rcxpony/sparkle
fixes
This commit is contained in:
parent
b0ec03ba36
commit
ff66de918f
@ -10,6 +10,8 @@ set(SOURCE sources/main.cpp)
|
|||||||
set(LIBS ${CMAKE_SOURCE_DIR}/libs/)
|
set(LIBS ${CMAKE_SOURCE_DIR}/libs/)
|
||||||
set(INCLUDE ${CMAKE_SOURCE_DIR}/include/)
|
set(INCLUDE ${CMAKE_SOURCE_DIR}/include/)
|
||||||
set(TESTS ${CMAKE_SOURCE_DIR}/tests)
|
set(TESTS ${CMAKE_SOURCE_DIR}/tests)
|
||||||
|
set(ADDITIONAL_CXX_FLAGS_DEBUG "-pipe -Wall -Wextra -O0 -fsanitize=address")
|
||||||
|
set(ADDITIONAL_CXX_FLAGS_RELEASE "-march=native -pipe -Wall -fsanitize=address -Wextra -O2 -flto")
|
||||||
|
|
||||||
find_package(CURL REQUIRED)
|
find_package(CURL REQUIRED)
|
||||||
find_path(IXWEBSOCKET_INCLUDE_DIR ixwebsocket)
|
find_path(IXWEBSOCKET_INCLUDE_DIR ixwebsocket)
|
||||||
@ -31,11 +33,11 @@ endif()
|
|||||||
|
|
||||||
if(CMAKE_BUILD_TYPE)
|
if(CMAKE_BUILD_TYPE)
|
||||||
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||||
set(CMAKE_CXX_FLAGS "-march=native -O0 -pipe -Wall -Werror")
|
set(CMAKE_CXX_FLAGS "${ADDITIONAL_CXX_FLAGS_DEBUG}")
|
||||||
add_definitions(-DDEBUG)
|
add_definitions(-DDEBUG)
|
||||||
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
|
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||||
add_definitions(-DRELEASE)
|
add_definitions(-DRELEASE)
|
||||||
set(CMAKE_CXX_FLAGS "-march=native -O2 -pipe -Wall -Werror")
|
set(CMAKE_CXX_FLAGS "${ADDITIONAL_CXX_FLAGS_RELEASE}")
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef INCLUDE_NET_H_
|
#ifndef INCLUDE_NET_H_
|
||||||
#define INCLUDE_NET_H_
|
#define INCLUDE_NET_H_
|
||||||
#include <gateway/Websocket.hpp>
|
#include <gateway/Websocket.hpp>
|
||||||
#include <tls/Network.hpp>
|
#include <network/Network.hpp>
|
||||||
#endif
|
#endif
|
@ -20,14 +20,14 @@ public:
|
|||||||
global_name(functions::isNull(d["author"]["global_name"])),
|
global_name(functions::isNull(d["author"]["global_name"])),
|
||||||
id(d["author"]["id"]),
|
id(d["author"]["id"]),
|
||||||
content(d["content"]),
|
content(d["content"]),
|
||||||
avatar(data["d"]["author"]["avatar"]),
|
avatar(d["author"]["avatar"]),
|
||||||
guild_id(data["d"]["guild_id"]),
|
guild_id(d["guild_id"]),
|
||||||
discriminator(data["d"]["author"]["discriminator"]),
|
discriminator(d["author"]["discriminator"]),
|
||||||
message_id(data["d"]["id"]),
|
message_id(d["id"]),
|
||||||
isPinned(data["d"]["pinned"]),
|
isPinned(d["pinned"]),
|
||||||
isBot(d["author"].contains("bot") ? d["author"]["bot"].get<bool>() : false) {};
|
isBot(d["author"].contains("bot") ? d["author"]["bot"].get<bool>() : false) {};
|
||||||
std::string send(const nlohmann::json& msg) {
|
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());
|
return req.request(HttpMethods::POST, DiscordEndpoints::details::latest + "/channels/" + d["channel_id"].get<std::string>() + "/messages", msg.dump());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
@ -104,12 +104,14 @@ public:
|
|||||||
int getIntents() const {
|
int getIntents() const {
|
||||||
return WebSocket::intents;
|
return WebSocket::intents;
|
||||||
}
|
}
|
||||||
void on(const std::string&& event, std::function<void(const nlohmann::json&)> handler) {
|
void on(const std::string& event, std::function<void(const nlohmann::json&)> handler = nullptr) {
|
||||||
eventHandlers[event] = [handler](const nlohmann::json& message) {
|
eventHandlers[event] = [handler](const nlohmann::json& message) {
|
||||||
|
if (handler) {
|
||||||
handler(message.get<nlohmann::json>());
|
handler(message.get<nlohmann::json>());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
void once(const std::string&& event, std::function<void(const nlohmann::json&)> handler) {
|
void once(const std::string& event, std::function<void(const nlohmann::json&)> handler) {
|
||||||
eventHandlers[event] = [event, handler, isCalled = false](const nlohmann::json& message) mutable {
|
eventHandlers[event] = [event, handler, isCalled = false](const nlohmann::json& message) mutable {
|
||||||
isCalled == false ? isCalled = true : 0, handler(message.get<nlohmann::json>());
|
isCalled == false ? isCalled = true : 0, handler(message.get<nlohmann::json>());
|
||||||
};
|
};
|
||||||
|
@ -9,7 +9,7 @@ enum level { INFO, WARNING, ERROR, CRITICAL };
|
|||||||
enum type { WEBSOCKET, NETWORK, API };
|
enum type { WEBSOCKET, NETWORK, API };
|
||||||
class Log {
|
class Log {
|
||||||
public:
|
public:
|
||||||
static void create(level lvl, type t, const std::string& message) {
|
static void create([[maybe_unused]] const level& lvl, [[maybe_unused]] const type& t, [[maybe_unused]] const std::string& message) {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
std::string color;
|
std::string color;
|
||||||
switch (lvl) {
|
switch (lvl) {
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
if (argc != 3) return -1;
|
if (argc != 3) return -1;
|
||||||
WebSocket* bot = &WebSocket::getInstance(argv[2], GatewayIntents::AllIntents);
|
WebSocket* bot = &WebSocket::getInstance(argv[2], GatewayIntents::AllIntents);
|
||||||
bot->on(GatewayEvents::READY, [](const Discord<Message, User>& a) {
|
bot->on(GatewayEvents::READY, [](const nlohmann::json&) {
|
||||||
std::cout << DiscordEndpoints::details::latest << std::endl;
|
std::cout << DiscordEndpoints::details::latest << std::endl;
|
||||||
});
|
});
|
||||||
bot->on(GatewayEvents::MESSAGE_CREATE, [](const Discord<Message, User, Author, Message::Api>& msg) {
|
bot->on(GatewayEvents::MESSAGE_CREATE, [](const Discord<Message, User, Author, Message::Api>& msg) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user