mirror of
https://gitlab.com/niansa/dpplogger.git
synced 2025-03-06 20:48:29 +01:00
Implemented bulk message deletion
This commit is contained in:
parent
6e9afab45c
commit
108853c190
1 changed files with 14 additions and 9 deletions
23
main.cpp
23
main.cpp
|
@ -275,8 +275,8 @@ protected:
|
||||||
<< data["id"].asString() << std::to_string(time(nullptr)) << is_initial << data["name"].asString()
|
<< data["id"].asString() << std::to_string(time(nullptr)) << is_initial << data["name"].asString()
|
||||||
<< data["owner_id"].asString() << !is_deleted;
|
<< data["owner_id"].asString() << !is_deleted;
|
||||||
}
|
}
|
||||||
void insertGuildDelete(const Json::Value& data) {
|
void insertGuildDelete(Discord::Snowflake id) {
|
||||||
auto cached_data = cache.fetch(data["id"]);
|
auto cached_data = cache.fetch(id);
|
||||||
insertGuildUpdate(cached_data, false, true);
|
insertGuildUpdate(cached_data, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -372,6 +372,7 @@ protected:
|
||||||
" VALUES (?, ?, ?, ?, ?, ? );"
|
" VALUES (?, ?, ?, ?, ?, ? );"
|
||||||
<< data["id"].asString() << type << data["channel_id"].asString() << data["author"]["id"].asString()
|
<< data["id"].asString() << type << data["channel_id"].asString() << data["author"]["id"].asString()
|
||||||
<< (type==19?data["referenced_message"]["id"].asString():std::optional<std::string>()) << std::to_string(time(nullptr));
|
<< (type==19?data["referenced_message"]["id"].asString():std::optional<std::string>()) << std::to_string(time(nullptr));
|
||||||
|
if (has_content) insertMessageContent(data, false);
|
||||||
} else {
|
} else {
|
||||||
db << "UPDATE messages "
|
db << "UPDATE messages "
|
||||||
"SET is_edited = 1, update_timestamp = ? "
|
"SET is_edited = 1, update_timestamp = ? "
|
||||||
|
@ -380,11 +381,11 @@ protected:
|
||||||
if (has_content) insertMessageContent(data, false);
|
if (has_content) insertMessageContent(data, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void insertMessageDelete(const Json::Value& data) {
|
void insertMessageDelete(const std::string& id) {
|
||||||
db << "UPDATE messages "
|
db << "UPDATE messages "
|
||||||
"SET is_deleted = 1, deletion_timestamp = ? "
|
"SET is_deleted = 1, deletion_timestamp = ? "
|
||||||
"WHERE id = ?;"
|
"WHERE id = ?;"
|
||||||
<< std::to_string(time(nullptr)) << data["id"].asString();
|
<< std::to_string(time(nullptr)) << id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -397,8 +398,8 @@ protected:
|
||||||
<< std::to_string(time(nullptr)) << is_initial << data["type"].asInt() << GetJSONAsOptionalString(data["name"])
|
<< std::to_string(time(nullptr)) << is_initial << data["type"].asInt() << GetJSONAsOptionalString(data["name"])
|
||||||
<< GetJSONAsOptionalString(data["topic"]) << is_deleted;
|
<< GetJSONAsOptionalString(data["topic"]) << is_deleted;
|
||||||
}
|
}
|
||||||
void insertChannelDelete(const Json::Value& data) {
|
void insertChannelDelete(Discord::Snowflake id) {
|
||||||
auto cached_data = cache.fetch(data["id"]);
|
auto cached_data = cache.fetch(id);
|
||||||
insertChannelUpdate(cached_data, false, true);
|
insertChannelUpdate(cached_data, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -418,14 +419,18 @@ protected:
|
||||||
insertGuildUpdate(data, false);
|
insertGuildUpdate(data, false);
|
||||||
cache.store(std::move(data));
|
cache.store(std::move(data));
|
||||||
} else if (intent == "GUILD_DELETE") [[unlikely]] {
|
} else if (intent == "GUILD_DELETE") [[unlikely]] {
|
||||||
insertGuildDelete(data);
|
insertGuildDelete(data["id"]);
|
||||||
}
|
}
|
||||||
else if (intent == "MESSAGE_CREATE") [[likely]] {
|
else if (intent == "MESSAGE_CREATE") [[likely]] {
|
||||||
processMessage(std::move(data));
|
processMessage(std::move(data));
|
||||||
} else if (intent == "MESSAGE_UPDATE") [[likely]] {
|
} else if (intent == "MESSAGE_UPDATE") [[likely]] {
|
||||||
insertMessageUpdate(data, false);
|
insertMessageUpdate(data, false);
|
||||||
} else if (intent == "MESSAGE_DELETE") {
|
} else if (intent == "MESSAGE_DELETE") {
|
||||||
insertMessageDelete(data);
|
insertMessageDelete(data["id"].asString());
|
||||||
|
} else if (intent == "MESSAGE_DELETE_BULK") {
|
||||||
|
for (const auto& id : data["ids"]) {
|
||||||
|
insertMessageDelete(id.asString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (intent == "CHANNEL_CREATE") [[unlikely]] {
|
else if (intent == "CHANNEL_CREATE") [[unlikely]] {
|
||||||
insertChannelUpdate(data, true);
|
insertChannelUpdate(data, true);
|
||||||
|
@ -434,7 +439,7 @@ protected:
|
||||||
insertChannelUpdate(data, false);
|
insertChannelUpdate(data, false);
|
||||||
cache.store(std::move(data));
|
cache.store(std::move(data));
|
||||||
} else if (intent == "CHANNEL_DELETE") [[unlikely]] {
|
} else if (intent == "CHANNEL_DELETE") [[unlikely]] {
|
||||||
insertChannelDelete(data);
|
insertChannelDelete(data["id"]);
|
||||||
}
|
}
|
||||||
else if (intent == "GUILD_MEMBER_ADD" || intent == "GUILD_MEMBER_UDATE") [[unlikely]] {
|
else if (intent == "GUILD_MEMBER_ADD" || intent == "GUILD_MEMBER_UDATE") [[unlikely]] {
|
||||||
auto guild_id = std::move(data["guild_id"]);
|
auto guild_id = std::move(data["guild_id"]);
|
||||||
|
|
Loading…
Add table
Reference in a new issue