diff --git a/src/core/settings.cpp b/src/core/settings.cpp index 3acdd10..7e9528e 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -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 guard(m_mutex); + for (auto guild = m_guilds.begin(); guild != m_guilds.end(); guild++) { + if (guild->id == guild_id) { + m_guilds.erase(guild); return; } } diff --git a/src/core/settings.h b/src/core/settings.h index 48afdfc..fe6b219 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -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 */ diff --git a/src/core/slashcommands.cpp b/src/core/slashcommands.cpp index 0f78910..37ca996 100644 --- a/src/core/slashcommands.cpp +++ b/src/core/slashcommands.cpp @@ -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)); }