forked from rcxpony/sparkle
for each
This commit is contained in:
parent
5a34d87814
commit
6e0d3ace47
@ -1,6 +1,7 @@
|
|||||||
Checks: >
|
Checks:
|
||||||
|
'-*,
|
||||||
clang-analyzer-*,
|
clang-analyzer-*,
|
||||||
modernize-*,
|
modernize-*,
|
||||||
performance-*,
|
performance-*,
|
||||||
bugprone-*,
|
bugprone-*,
|
||||||
cppcoreguidelines-*
|
cppcoreguidelines-*'
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
#include "websocket.hpp"
|
#include "websocket.hpp"
|
||||||
void EventEmitter::emit(const std::string& event, const nlohmann::json& data) {
|
void EventEmitter::emit(const std::string& event, const nlohmann::json& data) {
|
||||||
if (auto it = handlers.find(event); it != handlers.end()) {
|
if (auto it = handlers.find(event); it != handlers.end()) {
|
||||||
for (const auto& handler : it->second) {
|
std::for_each(it->second.begin(), it->second.end(), [&data](const auto& handler) {
|
||||||
handler(data);
|
handler(data);
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void EventEmitter::getEvents() {
|
void EventEmitter::getEvents() {
|
||||||
@ -30,9 +30,9 @@ void EventEmitter::off(const std::string& event, eventHandlers handler) {
|
|||||||
auto it = handlers.find(event);
|
auto it = handlers.find(event);
|
||||||
if (it != handlers.end()) {
|
if (it != handlers.end()) {
|
||||||
auto& vec = it->second;
|
auto& vec = it->second;
|
||||||
vec.erase(std::remove_if(vec.begin(), vec.end(), [&handler](const eventHandlers& h) {
|
vec.erase(std::ranges::remove_if(vec, [&handler](const eventHandlers& h) {
|
||||||
return h.target<eventHandlers>() == handler.target<eventHandlers>();
|
return h.target<eventHandlers>() == handler.target<eventHandlers>();
|
||||||
}), vec.end());
|
}).begin(), vec.end());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WebSocket::WebSocket(const std::string& token, int intents, bool isBot) : token(token), intents(intents), isBot(isBot) {
|
WebSocket::WebSocket(const std::string& token, int intents, bool isBot) : token(token), intents(intents), isBot(isBot) {
|
||||||
@ -55,7 +55,7 @@ WebSocket::WebSocket(const std::string& token, int intents, bool isBot) : token(
|
|||||||
}
|
}
|
||||||
})},
|
})},
|
||||||
{"status", "idle"},
|
{"status", "idle"},
|
||||||
{"since", 91879201},
|
{"since", 0},
|
||||||
{"afk", false}
|
{"afk", false}
|
||||||
}}
|
}}
|
||||||
}}
|
}}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#ifndef NETWORK_WEBSOCKET_HPP_
|
#ifndef NETWORK_WEBSOCKET_HPP_
|
||||||
#define NETWORK_WEBSOCKET_HPP_
|
#define NETWORK_WEBSOCKET_HPP_
|
||||||
#include <includes.hpp>
|
#include <includes.hpp>
|
||||||
|
#include <ranges>
|
||||||
#include <ixwebsocket/IXNetSystem.h>
|
#include <ixwebsocket/IXNetSystem.h>
|
||||||
#include <ixwebsocket/IXWebSocket.h>
|
#include <ixwebsocket/IXWebSocket.h>
|
||||||
class EventEmitter {
|
class EventEmitter {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user