From 8b35de51fc3df449813107badda99b929ee3e1d1 Mon Sep 17 00:00:00 2001 From: fluttershy <a@a.a> Date: Sat, 18 Jan 2025 00:13:18 +0500 Subject: [PATCH] test --- libs/gateway/Websocket.hpp | 4 ++-- sources/main.cpp | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/libs/gateway/Websocket.hpp b/libs/gateway/Websocket.hpp index 371815a..61ff9a8 100644 --- a/libs/gateway/Websocket.hpp +++ b/libs/gateway/Websocket.hpp @@ -183,12 +183,12 @@ public: int getIntents() const { return WebSocket::intents; } - void on(const int event, std::function<void(const json&)> handler) { + void on(const int event, std::function<void(const json&&)> handler) { eventHandlers[events[event].second] = [handler](const json& message) { handler(message.get<json>()); }; } - void once(const int event, std::function<void(const json&)> handler) { + void once(const int event, std::function<void(const json&&)> handler) { eventHandlers[events[event].second] = [event, handler, isCalled = false](const json& message) mutable { isCalled == false ? isCalled = true : 0, handler(message.get<json>()); }; diff --git a/sources/main.cpp b/sources/main.cpp index bd6adc9..8bb5047 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -1,5 +1,6 @@ #include <api.h> #include <includes.h> +#include <vector> int main(int argc, char* argv[]) { if (argc != 3) return -1; WebSocket* bot = &WebSocket::getInstance(argv[2], ALL_INTENTS); @@ -8,6 +9,11 @@ int main(int argc, char* argv[]) { g(0, msg.net)->send("939957962972229634", j("content", g(2, msg.net)->content())); } }); + bot->on(GatewayEvents::MESSAGE_CREATE, [](const Bot<Message, User, Author>& msg) { + if (!g(2, msg.net)->isBot()) { + g(0, msg.net)->send("939957962972229634", j("content", g(2, msg.net)->content())); + } + }); bot->start(); return 0; } \ No newline at end of file