This repository has been archived on 2025-03-15. You can view files and clone it, but cannot push or open issues or pull requests.
sparkle/libs/api/Bot.hpp

44 lines
1002 B
C++
Raw Normal View History

2024-12-31 02:20:56 +05:00
#ifndef API_BOT_HPP_
#define API_BOT_HPP_
2025-01-06 21:57:27 +05:00
#include <utils/types.hpp>
2024-12-31 02:20:56 +05:00
#include <string>
#include <iostream>
#include <tuple>
using std::string;
using std::cout;
using std::endl;
template<typename...Args>
class Bot {
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...>) {
net = std::make_tuple(std::make_unique<Args>(data)...);
}
json data;
public:
std::tuple<std::unique_ptr<Args>...> net;
Bot(const json& data) : data(data) {
initializeNets(data);
}
2025-01-06 22:18:30 +05:00
};
class BotHandler : Bot<> {
private:
json data;
public:
BotHandler(const json& data) : data(data), Bot(data) {};
2024-12-31 02:20:56 +05:00
string id() {
2025-01-06 22:18:30 +05:00
return data["d"]["id"];
2024-12-31 02:20:56 +05:00
}
bool isBot() {
try {
2025-01-06 22:18:30 +05:00
return data["d"]["bot"];
2024-12-31 02:20:56 +05:00
}
2025-01-13 22:30:24 +05:00
catch (...) {
2024-12-31 02:20:56 +05:00
return false;
}
}
};
#endif