mirror of
https://gitlab.com/niansa/SomeBot.git
synced 2025-03-06 20:48:26 +01:00
Delete globalchat messages across instances
This commit is contained in:
parent
28a97e5b8b
commit
c9b3a2d25f
1 changed files with 26 additions and 23 deletions
|
@ -447,29 +447,32 @@ public:
|
|||
return;
|
||||
}
|
||||
// Delete message everywhere
|
||||
bot->db << "SELECT id, guild_id FROM globalchat_messages "
|
||||
"WHERE primary_id = ?;"
|
||||
<< std::to_string(primary_id)
|
||||
>> [&](std::string message_id_str, std::string guild_id_str) {
|
||||
std::string channel_id_str;
|
||||
bot->db << "SELECT globalchat_channel FROM globalchat_guild_settings "
|
||||
"WHERE id = ?;"
|
||||
<< guild_id_str
|
||||
>> channel_id_str;
|
||||
// If guild is management guild, only mark it as deleted
|
||||
if (guild_id_str != std::to_string(bot->config.management_guild_id)) {
|
||||
bot->cluster.message_delete(message_id_str, channel_id_str);
|
||||
} else {
|
||||
bot->cluster.message_get(message_id_str, channel_id_str, [this](const dpp::confirmation_callback_t& ccb) {
|
||||
if (ccb.is_error()) {
|
||||
return;
|
||||
}
|
||||
auto msg = ccb.get<dpp::message>();
|
||||
msg.set_content(msg.content+"\n*(gelöscht)*");
|
||||
bot->cluster.message_edit(msg);
|
||||
});
|
||||
}
|
||||
};
|
||||
auto [bots, bots_lock] = bot->get_locked_property<std::vector<Bot*>>("main_all_instances");
|
||||
for (auto bot : *bots) {
|
||||
bot->db << "SELECT id, guild_id FROM globalchat_messages "
|
||||
"WHERE primary_id = ?;"
|
||||
<< std::to_string(primary_id)
|
||||
>> [&, bot](std::string message_id_str, std::string guild_id_str) {
|
||||
std::string channel_id_str;
|
||||
bot->db << "SELECT globalchat_channel FROM globalchat_guild_settings "
|
||||
"WHERE id = ?;"
|
||||
<< guild_id_str
|
||||
>> channel_id_str;
|
||||
// If guild is management guild, only mark it as deleted
|
||||
if (guild_id_str != std::to_string(bot->config.management_guild_id)) {
|
||||
bot->cluster.message_delete(message_id_str, channel_id_str);
|
||||
} else {
|
||||
bot->cluster.message_get(message_id_str, channel_id_str, [this, bot](const dpp::confirmation_callback_t& ccb) {
|
||||
if (ccb.is_error()) {
|
||||
return;
|
||||
}
|
||||
auto msg = ccb.get<dpp::message>();
|
||||
msg.set_content(msg.content+"\n*(gelöscht)*");
|
||||
bot->cluster.message_edit(msg);
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
// Report success
|
||||
event.reply(dpp::message("Okay!").set_flags(dpp::message_flags::m_ephemeral));
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue