This commit is contained in:
fluttershy 2025-01-18 00:13:18 +05:00
parent d113d303a2
commit 8b35de51fc
2 changed files with 8 additions and 2 deletions

View File

@ -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>());
};

View File

@ -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;
}