Compare commits

...

2 Commits

Author SHA1 Message Date
fluttershy
a72a3e3869 Merge pull request 'add cxxopts and change args handling' (#2) from lame_lexem/sparkle:main into main
Reviewed-on: http://applejack.ygg/fluttershy/sparkle/pulls/2
2025-01-25 15:22:54 +01:00
lexeyOK
728c65b8b3 add cxxopts and change args handling
this adds library cxxopts in utils/cxxopts.hpp and adds several flags
(version, help, token) we should foind how to update the vesrion in the
furute
2025-01-25 18:49:20 +05:00
2 changed files with 2963 additions and 6 deletions

2930
libs/utils/cxxopts.hpp Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,18 +1,45 @@
#include <utils/cxxopts.hpp>
#include <api.hpp>
#include <includes.hpp>
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<User>& b) {
auto& [user] = b.ctx();
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")) {
std::cout << "sparkle version 0.1" << std::endl;
return 0;
}
if (result.count("help")){
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();
std::cout << nlohmann::json::parse(user->me())["username"].get<std::string>() << std::endl;
});
bot->on(GatewayEvents::MESSAGE_CREATE, [](const Discord<Message, User, Author, Message::Api>& msg) {
const auto& [message, user, author, _] = msg.ctx();
bot->on(GatewayEvents::MESSAGE_CREATE, [](const Discord<Message, User, Author>& msg) {
const auto& [message, user, author] = msg.ctx();
if (!author->isBot) {
message->send("939957962972229634", message->pack("content", author->avatar));
}
});
bot->start();
return 0;
}