Compare commits
No commits in common. "be0be09a24aa20ffd520cd0a37f8f474f9c2399e" and "8ae437bc77a6b17879f1aa3d0b30467414aa33e2" have entirely different histories.
be0be09a24
...
8ae437bc77
@ -8,10 +8,28 @@ set(SOURCE sources/main.cpp)
|
||||
set(LIBS ${CMAKE_SOURCE_DIR}/libs/)
|
||||
set(INCLUDE ${CMAKE_SOURCE_DIR}/include/)
|
||||
set(TESTS ${CMAKE_SOURCE_DIR}/tests)
|
||||
set(CMAKE_C_COMPILER "clang")
|
||||
set(CMAKE_CXX_COMPILER "clang++")
|
||||
|
||||
find_package(CURL REQUIRED)
|
||||
find_path(IXWEBSOCKET_INCLUDE_DIR ixwebsocket)
|
||||
find_library(IXWEBSOCKET_LIBRARIES ixwebsocket)
|
||||
find_program(CMAKE_C_COMPILER clang)
|
||||
find_program(CLANG_CXX_COMPILER clang++)
|
||||
|
||||
message(STATUS "ixwebsocket: ${IXWEBSOCKET_LIBRARIES}")
|
||||
message(STATUS "curl: ${CURL_LIBRARIES}")
|
||||
|
||||
if(NOT CMAKE_C_COMPILER OR NOT CLANG_CXX_COMPILER)
|
||||
message(STATUS "clang not found")
|
||||
set(CMAKE_C_COMPILER "gcc")
|
||||
set(CMAKE_CXX_COMPILER "g++")
|
||||
find_program(CMAKE_C_COMPILER clang)
|
||||
find_program(CLANG_CXX_COMPILER clang++)
|
||||
if(NOT CMAKE_C_COMPILER OR NOT CLANG_CXX_COMPILER)
|
||||
message(FATAL_ERROR "gcc not found")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT IXWEBSOCKET_INCLUDE_DIR OR NOT IXWEBSOCKET_LIBRARIES)
|
||||
message(FATAL_ERROR "ixwebsocket not found")
|
||||
@ -23,7 +41,7 @@ endif()
|
||||
|
||||
add_executable(${PROJECT_NAME} ${SOURCE})
|
||||
#add_library(sparkles STATIC ${SOURCE})
|
||||
#add_executable(tests ${TESTS}/tests.cpp)
|
||||
add_executable(tests ${TESTS}/tests.cpp)
|
||||
|
||||
#enable_testing()
|
||||
|
||||
@ -45,18 +63,18 @@ target_link_libraries(${PROJECT_NAME} PRIVATE
|
||||
${CURL_LIBRARIES}
|
||||
)
|
||||
|
||||
#target_include_directories(tests PRIVATE
|
||||
# ${LIBS}
|
||||
# ${INCLUDE}
|
||||
# ${IXWEBSOCKET_INCLUDE_DIR}
|
||||
# ${CURL_INCLUDE_DIRS}
|
||||
#)
|
||||
target_include_directories(tests PRIVATE
|
||||
${LIBS}
|
||||
${INCLUDE}
|
||||
${IXWEBSOCKET_INCLUDE_DIR}
|
||||
${CURL_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
#target_link_libraries(tests gtest
|
||||
# ${IXWEBSOCKET_LIBRARIES}
|
||||
# ${CURL_LIBRARIES}
|
||||
# gtest_main
|
||||
#)
|
||||
target_link_libraries(tests gtest
|
||||
${IXWEBSOCKET_LIBRARIES}
|
||||
${CURL_LIBRARIES}
|
||||
gtest_main
|
||||
)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||
|
@ -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,7 +8,8 @@ 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;
|
||||
@ -17,10 +18,6 @@ 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,8 +25,5 @@ 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(CRITICAL, NETWORK, "Failed to initialize CURL");
|
||||
Log::create(ERROR, NETWORK, "Failed to initialize CURL");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
@ -84,23 +84,23 @@ struct HttpMethods {
|
||||
static constexpr const char* OPTIONS = "OPTIONS";
|
||||
};
|
||||
struct ApiVersion {
|
||||
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;
|
||||
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;
|
||||
};
|
||||
struct DiscordEndpoints {
|
||||
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";
|
||||
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";
|
||||
struct details {
|
||||
static const inline std::string current = DiscordEndpoints::discord + ApiVersion::current;
|
||||
static const inline std::string latest = DiscordEndpoints::discord + ApiVersion::latest;
|
||||
static inline std::string current = DiscordEndpoints::discord + ApiVersion::current;
|
||||
static inline std::string latest = DiscordEndpoints::discord + ApiVersion::latest;
|
||||
};
|
||||
};
|
||||
enum GatewayIntents {
|
||||
|
@ -14,11 +14,21 @@ 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,5 +3,6 @@
|
||||
#define j(...) {{__VA_ARGS__}}
|
||||
#define je(...) {__VA_ARGS__}
|
||||
#define g(x, y) (std::get<x>(y))
|
||||
#define RELEASE
|
||||
#define ALL_INTENTS 131071
|
||||
#define DEBUG
|
||||
#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, [bot](const Discord<Message, User, Author>& msg) {
|
||||
msg.get<0>().send("939957962972229634", msg.get<0>().pack({ "content", msg.get<2>().content() }));
|
||||
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->start();
|
||||
return 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user