This commit is contained in:
fluttershy 2025-01-19 04:43:55 +05:00
parent 3f97369f03
commit d8cf6e742f

View File

@ -3,40 +3,45 @@
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
if (argc != 3) return -1; if (argc != 3) return -1;
WebSocket* bot = &WebSocket::getInstance(argv[2], GatewayIntents::AllIntents, false); WebSocket* bot = &WebSocket::getInstance(argv[2], GatewayIntents::AllIntents, false);
bot->on(GatewayEvents::READY, [](const Bot<Message, User, Author>& msg) { bot->on(GatewayEvents::READY, [](const Discord<Message, User, Author>& msg) {
std::string lastID = "1292591828888977589"; std::string lastID = "1221155685518278708";
while (true) { while (true) {
std::vector<std::string> ids; std::vector<std::string> ids;
std::cout << "Last ID: " << lastID << std::endl; std::cout << "Last ID: " << lastID << std::endl;
json js = json::parse(g(0, msg.net)->getMessages("956854968260890654", "100", lastID)); json js = json::parse(g(0, msg.net)->getMessages("956854968260890654", "100", lastID));
if (js.is_array() && !js.empty()) { if (js.is_array() && !js.empty()) {
int counter = 0;
for (const auto& message : js) { for (const auto& message : js) {
if (message["author"]["id"] == "956790566463614986") { if (message["author"]["id"] == "956790566463614986") {
std::cout << "My message ID: " << message["id"].get<std::string>() << std::endl; printf("\rMessage ID: %s %d", message["id"].get<std::string>().c_str(), ++counter);
ids.push_back(message["id"].get<std::string>()); ids.emplace_back(message["id"].get<std::string>());
} }
else {
lastID = message["id"].get<std::string>(); lastID = message["id"].get<std::string>();
} }
}
cout << endl;
if (ids.size() > 1) { if (ids.size() > 1) {
for (size_t x = 0; x < ids.size(); x++) { for (unsigned long x = 0; x < ids.size(); x++) {
try { try {
json jss = json::parse(g(0, msg.net)->deleteMessage("956854968260890654", ids[x])); json jss = json::parse(g(0, msg.net)->deleteMessage("956854968260890654", ids[x]));
if (jss["code"].get<string>() == "20028") { if (jss["code"].get<string>() == "20028") {
std::this_thread::sleep_for(10s); std::this_thread::sleep_for(15s);
} }
std::cout << "Delete response: " << jss["message"] << ":" << jss["code"] << std::endl; std::cout << "Delete response: " << jss["message"] << ":" << jss["code"] << std::endl;
} }
catch (...) { catch (...) {
std::cout << "DELETED" << std::endl; std::cout << "\rDeleted ID: " << ids[x] << " " << x + 1;
std::cout.flush();
} }
std::this_thread::sleep_for(std::chrono::milliseconds(500)); std::this_thread::sleep_for(200ms);
} }
cout << endl;
} }
} }
else { else {
std::cout << "No messages found or error in response." << std::endl; std::cout << "No messages found or error in response." << std::endl;
} }
//std::this_thread::sleep_for(std::chrono::milliseconds(10));
} }
}); });
bot->start(); bot->start();