forked from rcxpony/sparkle
small fixes
This commit is contained in:
parent
d64486c624
commit
61a4ce5e61
@ -18,4 +18,4 @@ target_link_libraries(sparkle PRIVATE
|
|||||||
)
|
)
|
||||||
set(CMAKE_CXX_STANDARD 20)
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -flto -pipe")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -O2 -flto -pipe")
|
@ -25,6 +25,9 @@ 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);
|
||||||
|
}
|
||||||
string id() {
|
string id() {
|
||||||
return data["d"]["user"]["id"];
|
return data["d"]["user"]["id"];
|
||||||
}
|
}
|
||||||
|
@ -114,12 +114,12 @@ private:
|
|||||||
{"browser", "firefox"},
|
{"browser", "firefox"},
|
||||||
{"device", "firefox"}
|
{"device", "firefox"}
|
||||||
}},
|
}},
|
||||||
{"compress", 1},
|
//{"compress", 1},
|
||||||
{"presence", {
|
{"presence", {
|
||||||
{"activities", json::array({
|
{"activities", json::array({
|
||||||
{
|
{
|
||||||
{"name", "asdsadsadsadsa"},
|
//{"name", "asdsadsadsadsa"},
|
||||||
{"type", 2}
|
//{"type", 2}
|
||||||
}
|
}
|
||||||
})},
|
})},
|
||||||
{"status", "idle"},
|
{"status", "idle"},
|
||||||
@ -168,7 +168,7 @@ public:
|
|||||||
static WebSocket* getInstance(const std::string& token = "", const int intents = 0, bool bot = true) {
|
static WebSocket* getInstance(const std::string& token = "", const int intents = 0, bool bot = true) {
|
||||||
if (!instance) {
|
if (!instance) {
|
||||||
if (token.empty() || intents == 0) {
|
if (token.empty() || intents == 0) {
|
||||||
throw std::invalid_argument("Token and intents is empty.");
|
throw std::invalid_argument("Token or intents is empty.");
|
||||||
}
|
}
|
||||||
instance = new WebSocket(token, intents, bot);
|
instance = new WebSocket(token, intents, bot);
|
||||||
initialized = true;
|
initialized = true;
|
||||||
@ -187,7 +187,7 @@ public:
|
|||||||
}
|
}
|
||||||
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) {
|
eventHandlers[events[event].second] = [handler](const json& message) {
|
||||||
json eventData = message.get<json>();
|
const json& eventData = message.get<json>();
|
||||||
handler(eventData);
|
handler(eventData);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -208,9 +208,6 @@ public:
|
|||||||
}
|
}
|
||||||
}).detach();
|
}).detach();
|
||||||
}
|
}
|
||||||
void stop() {
|
|
||||||
connected = false;
|
|
||||||
}
|
|
||||||
void start() {
|
void start() {
|
||||||
while (1) std::this_thread::sleep_for(1ms);
|
while (1) std::this_thread::sleep_for(1ms);
|
||||||
}
|
}
|
||||||
|
@ -14,14 +14,13 @@ using namespace std;
|
|||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
if (argc != 5) return -1;
|
if (argc != 5) return -1;
|
||||||
WebSocket* bot = WebSocket::getInstance(argv[2], stoi(argv[4]), true);
|
WebSocket* bot = WebSocket::getInstance(argv[2], stoi(argv[4]), true);
|
||||||
bot->once(GatewayEvents::READY, [](const Bot<json>& 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, [bot](const Bot<json, Message, Author, EmbedBuilder>& msg) {
|
||||||
if (g(2, msg.net)->isBot() == false) {
|
if (g(2, msg.net)->isBot() == false) {
|
||||||
cout << g(1, msg.net)->send("939957962972229634", j("content", "test")) << endl;
|
g(1, msg.net)->send("939957962972229634", j("content", g(2, msg.net)->content()));
|
||||||
}
|
}
|
||||||
//bot->sendPresenceUpdate(UserStatus::Online, "sd");
|
|
||||||
});
|
});
|
||||||
bot->on(GatewayEvents::MESSAGE_REACTION_REMOVE, [bot](const Bot<Message>& msg) {
|
bot->on(GatewayEvents::MESSAGE_REACTION_REMOVE, [bot](const Bot<Message>& msg) {
|
||||||
g(0, msg.net)->send("939957962972229634", j("content", "bye"));
|
g(0, msg.net)->send("939957962972229634", j("content", "bye"));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user