Compare commits
8 Commits
8ae437bc77
...
be0be09a24
Author | SHA1 | Date | |
---|---|---|---|
![]() |
be0be09a24 | ||
![]() |
62de22e02e | ||
![]() |
626ddc1121 | ||
![]() |
c401269c4b | ||
![]() |
d8cf6e742f | ||
![]() |
e0c7c1fcd1 | ||
![]() |
cb7adad834 | ||
![]() |
f291deba36 |
@ -8,28 +8,10 @@ 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(CMAKE_C_COMPILER "clang")
|
|
||||||
set(CMAKE_CXX_COMPILER "clang++")
|
|
||||||
|
|
||||||
find_package(CURL REQUIRED)
|
find_package(CURL REQUIRED)
|
||||||
find_path(IXWEBSOCKET_INCLUDE_DIR ixwebsocket)
|
find_path(IXWEBSOCKET_INCLUDE_DIR ixwebsocket)
|
||||||
find_library(IXWEBSOCKET_LIBRARIES 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)
|
if(NOT IXWEBSOCKET_INCLUDE_DIR OR NOT IXWEBSOCKET_LIBRARIES)
|
||||||
message(FATAL_ERROR "ixwebsocket not found")
|
message(FATAL_ERROR "ixwebsocket not found")
|
||||||
@ -41,7 +23,7 @@ endif()
|
|||||||
|
|
||||||
add_executable(${PROJECT_NAME} ${SOURCE})
|
add_executable(${PROJECT_NAME} ${SOURCE})
|
||||||
#add_library(sparkles STATIC ${SOURCE})
|
#add_library(sparkles STATIC ${SOURCE})
|
||||||
add_executable(tests ${TESTS}/tests.cpp)
|
#add_executable(tests ${TESTS}/tests.cpp)
|
||||||
|
|
||||||
#enable_testing()
|
#enable_testing()
|
||||||
|
|
||||||
@ -63,18 +45,18 @@ target_link_libraries(${PROJECT_NAME} PRIVATE
|
|||||||
${CURL_LIBRARIES}
|
${CURL_LIBRARIES}
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(tests PRIVATE
|
#target_include_directories(tests PRIVATE
|
||||||
${LIBS}
|
# ${LIBS}
|
||||||
${INCLUDE}
|
# ${INCLUDE}
|
||||||
${IXWEBSOCKET_INCLUDE_DIR}
|
# ${IXWEBSOCKET_INCLUDE_DIR}
|
||||||
${CURL_INCLUDE_DIRS}
|
# ${CURL_INCLUDE_DIRS}
|
||||||
)
|
#)
|
||||||
|
|
||||||
target_link_libraries(tests gtest
|
#target_link_libraries(tests gtest
|
||||||
${IXWEBSOCKET_LIBRARIES}
|
# ${IXWEBSOCKET_LIBRARIES}
|
||||||
${CURL_LIBRARIES}
|
# ${CURL_LIBRARIES}
|
||||||
gtest_main
|
# gtest_main
|
||||||
)
|
#)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 20)
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||||
|
@ -9,7 +9,7 @@ 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) : data(data), web(WebSocket::getInstance()), req(NetworkManager::getInstance()) {};
|
||||||
string content() {
|
string content() {
|
||||||
try {
|
try {
|
||||||
return data["d"]["content"];
|
return data["d"]["content"];
|
||||||
|
@ -8,8 +8,7 @@ private:
|
|||||||
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>
|
template<unsigned long... Is>void initializeNetsImpl(const json& data, std::index_sequence<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;
|
json data;
|
||||||
@ -18,6 +17,10 @@ public:
|
|||||||
Discord(const json& data) : data(data) {
|
Discord(const json& data) : data(data) {
|
||||||
initializeNets(data);
|
initializeNets(data);
|
||||||
}
|
}
|
||||||
|
template<unsigned long Index>
|
||||||
|
auto& get() const {
|
||||||
|
return *std::get<Index>(net);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
class Bot {
|
class Bot {
|
||||||
private:
|
private:
|
||||||
|
@ -25,5 +25,8 @@ public:
|
|||||||
string deleteMessage(const string& channel_id, const string& message_id) {
|
string deleteMessage(const string& channel_id, const string& message_id) {
|
||||||
return req.request(HttpMethods::DELETE, DiscordEndpoints::details::latest + "/channels/" + channel_id + "/messages/" + 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
|
#endif
|
@ -16,7 +16,7 @@ private:
|
|||||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||||
curl = curl_easy_init();
|
curl = curl_easy_init();
|
||||||
if (!curl) {
|
if (!curl) {
|
||||||
Log::create(ERROR, NETWORK, "Failed to initialize CURL");
|
Log::create(CRITICAL, NETWORK, "Failed to initialize CURL");
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,23 +84,23 @@ struct HttpMethods {
|
|||||||
static constexpr const char* OPTIONS = "OPTIONS";
|
static constexpr const char* OPTIONS = "OPTIONS";
|
||||||
};
|
};
|
||||||
struct ApiVersion {
|
struct ApiVersion {
|
||||||
static inline std::string api = "/api/";
|
static const inline std::string api = "/api/";
|
||||||
static inline std::string v10 = "v10";
|
static const inline std::string v10 = "v10";
|
||||||
static inline std::string v9 = "v9";
|
static const inline std::string v9 = "v9";
|
||||||
static inline std::string v8 = "v8";
|
static const inline std::string v8 = "v8";
|
||||||
static inline std::string v7 = "v7";
|
static const inline std::string v7 = "v7";
|
||||||
static inline std::string v6 = "v6";
|
static const inline std::string v6 = "v6";
|
||||||
static inline std::string current = api + v6;
|
static const inline std::string current = api + v6;
|
||||||
static inline std::string latest = api + v10;
|
static const inline std::string latest = api + v10;
|
||||||
};
|
};
|
||||||
struct DiscordEndpoints {
|
struct DiscordEndpoints {
|
||||||
static inline std::string main_scheme = "https://";
|
static const inline std::string main_scheme = "https://";
|
||||||
static inline std::string discord = main_scheme + "discord.com";
|
static const inline std::string discord = main_scheme + "discord.com";
|
||||||
static inline std::string images = main_scheme + "cdn.discord.com";
|
static const inline std::string images = main_scheme + "cdn.discord.com";
|
||||||
static inline std::string media = main_scheme + "media.discord.com";
|
static const inline std::string media = main_scheme + "media.discord.com";
|
||||||
struct details {
|
struct details {
|
||||||
static inline std::string current = DiscordEndpoints::discord + ApiVersion::current;
|
static const inline std::string current = DiscordEndpoints::discord + ApiVersion::current;
|
||||||
static inline std::string latest = DiscordEndpoints::discord + ApiVersion::latest;
|
static const inline std::string latest = DiscordEndpoints::discord + ApiVersion::latest;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
enum GatewayIntents {
|
enum GatewayIntents {
|
||||||
|
@ -14,21 +14,11 @@ public:
|
|||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
std::string color;
|
std::string color;
|
||||||
switch (lvl) {
|
switch (lvl) {
|
||||||
case INFO:
|
case INFO: color = "\033[34;1m"; break;
|
||||||
color = "\033[34;1m";
|
case WARNING: color = "\033[33;1m"; break;
|
||||||
break;
|
case ERROR: color = "\033[31;1m"; break;
|
||||||
case WARNING:
|
case CRITICAL: color = "\033[31;1;2m"; break;
|
||||||
color = "\033[33;1m";
|
default: color = "\033[0m"; break;
|
||||||
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;
|
std::cout << color << "[" << getCurrentTime() << "][" << str(t) << "][" << str(lvl) << "] \033[0m" << message << "\033[0m" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
@ -3,6 +3,5 @@
|
|||||||
#define j(...) {{__VA_ARGS__}}
|
#define j(...) {{__VA_ARGS__}}
|
||||||
#define je(...) {__VA_ARGS__}
|
#define je(...) {__VA_ARGS__}
|
||||||
#define g(x, y) (std::get<x>(y))
|
#define g(x, y) (std::get<x>(y))
|
||||||
#define ALL_INTENTS 131071
|
#define RELEASE
|
||||||
#define DEBUG
|
|
||||||
#endif
|
#endif
|
@ -3,11 +3,11 @@
|
|||||||
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 Discord<Message, User>&a) {
|
||||||
cout << DiscordEndpoints::details::latest << endl;
|
cout << DiscordEndpoints::details::latest << endl;
|
||||||
});
|
});
|
||||||
bot->on(GatewayEvents::MESSAGE_CREATE, [](const Discord<Message, User, Author> msg) {
|
bot->on(GatewayEvents::MESSAGE_CREATE, [bot](const Discord<Message, User, Author>& msg) {
|
||||||
g(0, msg.net)->send("939957962972229634", j("content", g(2, msg.net)->content()));
|
msg.get<0>().send("939957962972229634", msg.get<0>().pack({ "content", msg.get<2>().content() }));
|
||||||
});
|
});
|
||||||
bot->start();
|
bot->start();
|
||||||
return 0;
|
return 0;
|
||||||
|
Reference in New Issue
Block a user