This commit is contained in:
fluttershy 2025-01-06 22:18:30 +05:00
parent eb239115d1
commit 209f2134ae
3 changed files with 15 additions and 13 deletions

View File

@ -24,15 +24,18 @@ public:
Bot(const json& data) : data(data) { Bot(const json& data) : data(data) {
initializeNets(data); initializeNets(data);
} }
auto& use(const int number) { };
return *std::get<number>(net); class BotHandler : Bot<> {
} private:
json data;
public:
BotHandler(const json& data) : data(data), Bot(data) {};
string id() { string id() {
return data["d"]["user"]["id"]; return data["d"]["id"];
} }
bool isBot() { bool isBot() {
try { try {
return data["d"]["user"]["bot"]; return data["d"]["bot"];
} }
catch (std::exception& e) { catch (std::exception& e) {
return false; return false;

View File

@ -128,11 +128,10 @@ private:
}} }}
}} }}
}; };
using namespace ix; ix::initNetSystem();
initNetSystem();
webSocket.setUrl("wss://gateway.discord.gg/?v=10&encoding=json"); webSocket.setUrl("wss://gateway.discord.gg/?v=10&encoding=json");
webSocket.setOnMessageCallback([this](const WebSocketMessagePtr& msg) { webSocket.setOnMessageCallback([this](const ix::WebSocketMessagePtr& msg) {
if (msg->type == WebSocketMessageType::Message) { if (msg->type == ix::WebSocketMessageType::Message) {
res = json::parse(msg->str); res = json::parse(msg->str);
res["s"].is_number() ? lastS = res["s"] : false; res["s"].is_number() ? lastS = res["s"] : false;
chngcol(std::string("WEBSOCKET: " + std::to_string(lastS) + " " + res["op"].dump() + " " + res["t"].dump()), 0, 0, 120); chngcol(std::string("WEBSOCKET: " + std::to_string(lastS) + " " + res["op"].dump() + " " + res["t"].dump()), 0, 0, 120);

View File

@ -17,12 +17,12 @@ int main(int argc, char* argv[]) {
bot->on(GatewayEvents::READY, [](const Bot<Message>& b) { bot->on(GatewayEvents::READY, [](const Bot<Message>& b) {
cout << "started" << endl; cout << "started" << endl;
}); });
bot->on(GatewayEvents::MESSAGE_CREATE, [bot](const Bot<json, Message, Author, EmbedBuilder>& msg) { bot->on(GatewayEvents::MESSAGE_CREATE, [](const Bot<Message, Author, EmbedBuilder>& msg) {
if (g(2, msg.net)->isBot() == false) { if (g(1, msg.net)->isBot() == false) {
g(1, msg.net)->send("939957962972229634", j("content", g(2, msg.net)->content())); g(0, msg.net)->send("939957962972229634", j("content", g(1, msg.net)->content()));
} }
}); });
bot->on(GatewayEvents::MESSAGE_REACTION_REMOVE, [bot](const Bot<Message>& msg) { bot->on(GatewayEvents::MESSAGE_REACTION_REMOVE, [](const Bot<Message>& msg) {
g(0, msg.net)->send("939957962972229634", g(0, msg.net)->send("939957962972229634",
j("content", "bye")); j("content", "bye"));
}); });