2025-01-25 18:49:20 +05:00
|
|
|
#include <utils/cxxopts.hpp>
|
2025-01-25 13:22:59 +05:00
|
|
|
#include <api.hpp>
|
|
|
|
#include <includes.hpp>
|
2024-12-31 04:46:39 +05:00
|
|
|
int main(int argc, char* argv[]) {
|
2025-01-25 18:49:20 +05:00
|
|
|
cxxopts::Options options("sparkle", "WIP discord bot library in C++");
|
|
|
|
options.add_options()
|
|
|
|
("h,help", "Print help")
|
|
|
|
("V,version", "Show version information")
|
|
|
|
("t,token", "Discord bot token", cxxopts::value<std::string>());
|
|
|
|
|
|
|
|
auto result = options.parse(argc, argv);
|
|
|
|
|
|
|
|
if (result.count("version")) {
|
2025-01-26 15:48:38 +05:00
|
|
|
std::cout << "sparkle version 0.3" << std::endl;
|
2025-01-25 18:49:20 +05:00
|
|
|
return 0;
|
|
|
|
}
|
2025-01-26 15:48:38 +05:00
|
|
|
|
|
|
|
if (result.count("help")) {
|
2025-01-25 18:49:20 +05:00
|
|
|
std::cout << options.help() << std::endl;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!result.contains("token")) {
|
|
|
|
std::cout << "\033[31mError: no token provided.\033[0m" << std::endl;
|
|
|
|
std::cout << options.help() << std::endl;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
WebSocket* bot = &WebSocket::getInstance(result["token"].as<std::string>(), GatewayIntents::AllIntents);
|
|
|
|
|
|
|
|
bot->on(GatewayEvents::READY, [](const Discord<User>& ctx) {
|
|
|
|
auto& [user] = ctx.ctx();
|
2025-01-25 17:21:44 +05:00
|
|
|
std::cout << nlohmann::json::parse(user->me())["username"].get<std::string>() << std::endl;
|
2025-01-19 04:41:20 +05:00
|
|
|
});
|
2025-01-25 18:49:20 +05:00
|
|
|
|
|
|
|
bot->on(GatewayEvents::MESSAGE_CREATE, [](const Discord<Message, User, Author>& msg) {
|
|
|
|
const auto& [message, user, author] = msg.ctx();
|
2025-01-25 17:21:44 +05:00
|
|
|
if (!author->isBot) {
|
2025-01-26 15:48:38 +05:00
|
|
|
message->send("939957962972229634", message->pack("content", author->channel_id));
|
2025-01-25 11:24:56 +05:00
|
|
|
}
|
2025-01-18 00:13:18 +05:00
|
|
|
});
|
2025-01-26 15:48:38 +05:00
|
|
|
bot->on(GatewayEvents::MESSAGE_REACTION_ADD, [](const Discord<Message>& msg) {
|
|
|
|
const auto& [message] = msg.ctx();
|
|
|
|
message->send("939957962972229634", message->pack("content", "test"));
|
|
|
|
});
|
2024-12-31 02:20:56 +05:00
|
|
|
bot->start();
|
|
|
|
return 0;
|
2025-01-19 04:41:20 +05:00
|
|
|
}
|