mirror of
https://github.com/Syping/dtranslatebot.git
synced 2024-11-22 13:50:22 +01:00
erase empty guilds from memory
This commit is contained in:
parent
0dbf987ff2
commit
92d9aba8d0
3 changed files with 28 additions and 8 deletions
|
@ -301,11 +301,22 @@ void settings::add_translatebot_webhook(dpp::snowflake webhook_id)
|
|||
m_webhookIds.push_back(webhook_id);
|
||||
}
|
||||
|
||||
void settings::erase_channel(guild *guild, dpp::snowflake channel_id)
|
||||
void settings::erase_channel(guild &guild, dpp::snowflake channel_id)
|
||||
{
|
||||
for (auto channel = guild->channel.begin(); channel != guild->channel.end(); channel++) {
|
||||
for (auto channel = guild.channel.begin(); channel != guild.channel.end(); channel++) {
|
||||
if (channel->id == channel_id) {
|
||||
guild->channel.erase(channel);
|
||||
guild.channel.erase(channel);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void settings::erase_guild(dpp::snowflake guild_id)
|
||||
{
|
||||
const std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
||||
for (auto guild = m_guilds.begin(); guild != m_guilds.end(); guild++) {
|
||||
if (guild->id == guild_id) {
|
||||
m_guilds.erase(guild);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,8 @@ namespace bot {
|
|||
void add_translatebot_webhook(dpp::snowflake webhook_id);
|
||||
|
||||
/* erase functions */
|
||||
static void erase_channel(guild *guild, dpp::snowflake channel_id);
|
||||
static void erase_channel(guild &guild, dpp::snowflake channel_id);
|
||||
void erase_guild(dpp::snowflake guild_id);
|
||||
void erase_translatebot_webhook(dpp::snowflake webhook_id);
|
||||
|
||||
/* get functions */
|
||||
|
|
|
@ -68,8 +68,12 @@ void bot::slashcommands::process_edit_command(dpp::cluster *bot, bot::settings::
|
|||
database->delete_channel(event.command.guild_id, event.command.channel_id);
|
||||
database->sync();
|
||||
|
||||
if (channel->targets.empty())
|
||||
settings->erase_channel(guild, event.command.channel_id);
|
||||
if (channel->targets.empty()) {
|
||||
settings->erase_channel(*guild, event.command.channel_id);
|
||||
if (guild->channel.empty()) {
|
||||
settings->erase_guild(event.command.guild_id);
|
||||
}
|
||||
}
|
||||
|
||||
event.reply(dpp::message("Deleteable targets have being deleted!").set_flags(dpp::m_ephemeral));
|
||||
}
|
||||
|
@ -97,8 +101,12 @@ void bot::slashcommands::process_edit_command(dpp::cluster *bot, bot::settings::
|
|||
database->delete_channel_target(event.command.guild_id, event.command.channel_id, target);
|
||||
database->sync();
|
||||
|
||||
if (channel->targets.empty())
|
||||
settings->erase_channel(guild, event.command.channel_id);
|
||||
if (channel->targets.empty()) {
|
||||
settings->erase_channel(*guild, event.command.channel_id);
|
||||
if (guild->channel.empty()) {
|
||||
settings->erase_guild(event.command.guild_id);
|
||||
}
|
||||
}
|
||||
|
||||
event.reply(dpp::message("Target have being deleted!").set_flags(dpp::m_ephemeral));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue