40 lines
958 B
C++
40 lines
958 B
C++
#ifndef API_BOT_HPP_
|
|
#define API_BOT_HPP_
|
|
#include <utils/json.hpp>
|
|
#include <string>
|
|
#include <exception>
|
|
#include <iostream>
|
|
#include <tuple>
|
|
using std::string;
|
|
using std::cout;
|
|
using std::endl;
|
|
using json = nlohmann::json;
|
|
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);
|
|
}
|
|
string id() {
|
|
return data["d"]["user"]["id"];
|
|
}
|
|
bool isBot() {
|
|
try {
|
|
return data["d"]["user"]["bot"];
|
|
}
|
|
catch (std::exception& e) {
|
|
return false;
|
|
}
|
|
}
|
|
};
|
|
#endif |