From 1b2bb85b3702d2b31d007b15be1ab1a0de6241c5 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Tue, 15 Aug 2023 23:24:29 +0200 Subject: [PATCH] Improved feature flag for server handling #334 --- .../configuration/feature_flags_settings.py | 11 +++++++++ .../achievements/achievements_module.py | 2 +- .../commands/achievements_group.py | 11 +++++++++ .../events/achievement_on_message_event.py | 12 ++++++++++ .../auto_role/command/auto_role_group.py | 24 +++++++++++++++++++ .../events/auto_role_on_raw_reaction_add.py | 9 +++++++ .../auto_role_on_raw_reaction_remove.py | 9 +++++++ .../boot_log/boot_log_on_ready_event.py | 7 ++++++ .../events/level_on_member_join_event.py | 13 +++++++++- .../level/events/level_on_message_event.py | 13 +++++++++- .../events/level_on_raw_reaction_add_event.py | 12 ++++++++++ .../level_on_raw_reaction_remove_event.py | 12 ++++++++++ .../level_on_voice_state_update_event.py | 13 +++++++++- 13 files changed, 144 insertions(+), 4 deletions(-) diff --git a/kdb-bot/src/bot_core/configuration/feature_flags_settings.py b/kdb-bot/src/bot_core/configuration/feature_flags_settings.py index 19aeb110..f4154f73 100644 --- a/kdb-bot/src/bot_core/configuration/feature_flags_settings.py +++ b/kdb-bot/src/bot_core/configuration/feature_flags_settings.py @@ -34,6 +34,17 @@ class FeatureFlagsSettings(ConfigurationModelABC): for flag in [f.value for f in FeatureFlagsEnum]: self._load_flag(kwargs, FeatureFlagsEnum(flag)) + @classmethod + def get_flag_from_dict(cls, flags: dict, key: FeatureFlagsEnum) -> bool: + def get_flag(): + if key.value not in cls._flags: + return False + return cls._flags[key.value] + + if key.value not in flags: + return get_flag() + return flags[key.value] + def get_flag(self, key: FeatureFlagsEnum) -> bool: if key.value not in self._flags: return False diff --git a/kdb-bot/src/modules/achievements/achievements_module.py b/kdb-bot/src/modules/achievements/achievements_module.py index dc59af6c..cfe1ce2b 100644 --- a/kdb-bot/src/modules/achievements/achievements_module.py +++ b/kdb-bot/src/modules/achievements/achievements_module.py @@ -14,7 +14,7 @@ from modules.achievements.events.achievement_on_message_event import Achievement class AchievementsModule(ModuleABC): def __init__(self, dc: DiscordCollectionABC): - ModuleABC.__init__(self, dc, FeatureFlagsEnum.auto_role_module) + ModuleABC.__init__(self, dc, FeatureFlagsEnum.achievements_module) def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC): pass diff --git a/kdb-bot/src/modules/achievements/commands/achievements_group.py b/kdb-bot/src/modules/achievements/commands/achievements_group.py index 189b8dae..b72366d5 100644 --- a/kdb-bot/src/modules/achievements/commands/achievements_group.py +++ b/kdb-bot/src/modules/achievements/commands/achievements_group.py @@ -1,4 +1,5 @@ import discord +from cpl_core.configuration import ConfigurationABC from cpl_discord.command import DiscordCommandABC from cpl_discord.service import DiscordBotServiceABC from cpl_translation import TranslatePipe @@ -6,16 +7,20 @@ from discord.ext import commands from discord.ext.commands import Context from bot_core.abc.message_service_abc import MessageServiceABC +from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum +from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings from bot_core.helper.command_checks import CommandChecks from bot_core.logging.command_logger import CommandLogger from bot_data.abc.server_repository_abc import ServerRepositoryABC from bot_data.abc.user_repository_abc import UserRepositoryABC +from bot_data.model.server_config import ServerConfig from modules.achievements.achievement_service import AchievementService class AchievementGroup(DiscordCommandABC): def __init__( self, + config: ConfigurationABC, logger: CommandLogger, message_service: MessageServiceABC, bot: DiscordBotServiceABC, @@ -26,6 +31,7 @@ class AchievementGroup(DiscordCommandABC): ): DiscordCommandABC.__init__(self) + self._config = config self._logger = logger self._message_service = message_service self._bot = bot @@ -45,6 +51,11 @@ class AchievementGroup(DiscordCommandABC): @CommandChecks.check_is_member_moderator() async def check(self, ctx: Context, member: discord.Member): self._logger.debug(__name__, f"Received command achievement check {ctx}") + server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild.id}") + if not FeatureFlagsSettings.get_flag_from_dict( + server_config.feature_flags, FeatureFlagsEnum.achievements_module + ): + return server = self._servers.get_server_by_discord_id(member.guild.id) user = self._users.get_user_by_discord_id_and_server_id(member.id, server.id) diff --git a/kdb-bot/src/modules/achievements/events/achievement_on_message_event.py b/kdb-bot/src/modules/achievements/events/achievement_on_message_event.py index 5b45cc5d..597475e0 100644 --- a/kdb-bot/src/modules/achievements/events/achievement_on_message_event.py +++ b/kdb-bot/src/modules/achievements/events/achievement_on_message_event.py @@ -1,18 +1,23 @@ import discord +from cpl_core.configuration import ConfigurationABC from cpl_core.database.context import DatabaseContextABC from cpl_core.logging import LoggerABC from cpl_discord.events import OnMessageABC from cpl_discord.service import DiscordBotServiceABC +from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum +from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings from bot_core.helper.event_checks import EventChecks from bot_data.abc.server_repository_abc import ServerRepositoryABC from bot_data.abc.user_repository_abc import UserRepositoryABC +from bot_data.model.server_config import ServerConfig from modules.achievements.achievement_service import AchievementService class AchievementOnMessageEvent(OnMessageABC): def __init__( self, + config: ConfigurationABC, logger: LoggerABC, bot: DiscordBotServiceABC, achievements: AchievementService, @@ -22,6 +27,7 @@ class AchievementOnMessageEvent(OnMessageABC): ): OnMessageABC.__init__(self) + self._config = config self._logger = logger self._bot = bot self._achievements = achievements @@ -31,6 +37,12 @@ class AchievementOnMessageEvent(OnMessageABC): @EventChecks.check_is_ready() async def on_message(self, message: discord.Message): + server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{message.guild.id}") + if not FeatureFlagsSettings.get_flag_from_dict( + server_config.feature_flags, FeatureFlagsEnum.achievements_module + ): + return + if message.author.bot: return diff --git a/kdb-bot/src/modules/auto_role/command/auto_role_group.py b/kdb-bot/src/modules/auto_role/command/auto_role_group.py index 3969aea9..7921256e 100644 --- a/kdb-bot/src/modules/auto_role/command/auto_role_group.py +++ b/kdb-bot/src/modules/auto_role/command/auto_role_group.py @@ -1,6 +1,7 @@ from typing import List as TList import discord +from cpl_core.configuration import ConfigurationABC from cpl_core.database.context import DatabaseContextABC from cpl_discord.command import DiscordCommandABC from cpl_discord.service import DiscordBotServiceABC @@ -12,18 +13,22 @@ from discord.ext.commands import Context from bot_core.abc.client_utils_abc import ClientUtilsABC from bot_core.abc.message_service_abc import MessageServiceABC +from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum +from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings from bot_core.helper.command_checks import CommandChecks from bot_core.logging.command_logger import CommandLogger from bot_data.abc.auto_role_repository_abc import AutoRoleRepositoryABC from bot_data.abc.server_repository_abc import ServerRepositoryABC from bot_data.model.auto_role import AutoRole from bot_data.model.auto_role_rule import AutoRoleRule +from bot_data.model.server_config import ServerConfig from modules.permission.abc.permission_service_abc import PermissionServiceABC class AutoRoleGroup(DiscordCommandABC): def __init__( self, + config: ConfigurationABC, logger: CommandLogger, message_service: MessageServiceABC, bot: DiscordBotServiceABC, @@ -36,6 +41,7 @@ class AutoRoleGroup(DiscordCommandABC): ): DiscordCommandABC.__init__(self) + self._config = config self._logger = logger self._message_service = message_service self._bot = bot @@ -69,6 +75,9 @@ class AutoRoleGroup(DiscordCommandABC): @CommandChecks.check_is_member_moderator() async def list(self, ctx: Context, wait: int = None): self._logger.debug(__name__, f"Received command auto-role list {ctx}") + server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild_id}") + if not FeatureFlagsSettings.get_flag_from_dict(server_config.feature_flags, FeatureFlagsEnum.auto_role_module): + return if ctx.guild is None: return @@ -110,6 +119,9 @@ class AutoRoleGroup(DiscordCommandABC): @CommandChecks.check_is_member_moderator() async def add(self, ctx: Context, channel: discord.TextChannel, message_id: str): self._logger.debug(__name__, f"Received command auto-role add {ctx} {message_id}") + server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild_id}") + if not FeatureFlagsSettings.get_flag_from_dict(server_config.feature_flags, FeatureFlagsEnum.auto_role_module): + return message = ( List( @@ -170,6 +182,9 @@ class AutoRoleGroup(DiscordCommandABC): @CommandChecks.check_is_member_moderator() async def remove(self, ctx: Context, auto_role: int): self._logger.debug(__name__, f"Received command auto-role remove {ctx} {auto_role}") + server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild_id}") + if not FeatureFlagsSettings.get_flag_from_dict(server_config.feature_flags, FeatureFlagsEnum.auto_role_module): + return auto_role_from_db = self._auto_roles.find_auto_role_by_id(auto_role) if auto_role_from_db is None: @@ -210,6 +225,9 @@ class AutoRoleGroup(DiscordCommandABC): @CommandChecks.check_is_member_moderator() async def list(self, ctx: Context, auto_role: int, wait: int = None): self._logger.debug(__name__, f"Received command auto-role rule list {ctx}") + server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild_id}") + if not FeatureFlagsSettings.get_flag_from_dict(server_config.feature_flags, FeatureFlagsEnum.auto_role_module): + return embed = discord.Embed( title=self._t.transform("modules.auto_role.list.title"), @@ -262,6 +280,9 @@ class AutoRoleGroup(DiscordCommandABC): @CommandChecks.check_is_member_moderator() async def add(self, ctx: Context, auto_role: int, emoji_name: str, role_id: str): self._logger.debug(__name__, f"Received command auto-role add {ctx} {auto_role}") + server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild_id}") + if not FeatureFlagsSettings.get_flag_from_dict(server_config.feature_flags, FeatureFlagsEnum.auto_role_module): + return emoji = discord.utils.get(self._bot.emojis, name=emoji_name) if emoji is None: @@ -354,6 +375,9 @@ class AutoRoleGroup(DiscordCommandABC): @CommandChecks.check_is_member_moderator() async def remove(self, ctx: Context, auto_role_rule: int): self._logger.debug(__name__, f"Received command auto-role remove {ctx} {auto_role_rule}") + server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild_id}") + if not FeatureFlagsSettings.get_flag_from_dict(server_config.feature_flags, FeatureFlagsEnum.auto_role_module): + return auto_role_from_db = self._auto_roles.get_auto_role_rule_by_id(auto_role_rule) if auto_role_from_db is None: diff --git a/kdb-bot/src/modules/auto_role/events/auto_role_on_raw_reaction_add.py b/kdb-bot/src/modules/auto_role/events/auto_role_on_raw_reaction_add.py index 72566c40..f5d14804 100644 --- a/kdb-bot/src/modules/auto_role/events/auto_role_on_raw_reaction_add.py +++ b/kdb-bot/src/modules/auto_role/events/auto_role_on_raw_reaction_add.py @@ -1,17 +1,22 @@ +from cpl_core.configuration import ConfigurationABC from cpl_core.logging import LoggerABC from cpl_discord.events.on_raw_reaction_add_abc import OnRawReactionAddABC from cpl_discord.service import DiscordBotServiceABC from discord import RawReactionActionEvent +from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum +from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings from bot_core.helper.event_checks import EventChecks from bot_data.abc.auto_role_repository_abc import AutoRoleRepositoryABC from bot_data.abc.server_repository_abc import ServerRepositoryABC +from bot_data.model.server_config import ServerConfig from modules.auto_role.helper.auto_role_reaction_handler import AutoRoleReactionHandler class AutoRoleOnRawReactionAddEvent(OnRawReactionAddABC): def __init__( self, + config: ConfigurationABC, logger: LoggerABC, bot: DiscordBotServiceABC, servers: ServerRepositoryABC, @@ -20,6 +25,7 @@ class AutoRoleOnRawReactionAddEvent(OnRawReactionAddABC): ): OnRawReactionAddABC.__init__(self) + self._config = config self._logger = logger self._bot = bot self._servers = servers @@ -29,6 +35,9 @@ class AutoRoleOnRawReactionAddEvent(OnRawReactionAddABC): @EventChecks.check_is_ready() async def on_raw_reaction_add(self, payload: RawReactionActionEvent): self._logger.debug(__name__, f"Module {type(self)} started") + server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{payload.guild_id}") + if not FeatureFlagsSettings.get_flag_from_dict(server_config.feature_flags, FeatureFlagsEnum.auto_role_module): + return await self._reaction_handler.handle(payload, "add") diff --git a/kdb-bot/src/modules/auto_role/events/auto_role_on_raw_reaction_remove.py b/kdb-bot/src/modules/auto_role/events/auto_role_on_raw_reaction_remove.py index 394c9578..a174c8f5 100644 --- a/kdb-bot/src/modules/auto_role/events/auto_role_on_raw_reaction_remove.py +++ b/kdb-bot/src/modules/auto_role/events/auto_role_on_raw_reaction_remove.py @@ -1,17 +1,22 @@ +from cpl_core.configuration import ConfigurationABC from cpl_core.logging import LoggerABC from cpl_discord.events.on_raw_reaction_remove_abc import OnRawReactionRemoveABC from cpl_discord.service import DiscordBotServiceABC from discord import RawReactionActionEvent +from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum +from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings from bot_core.helper.event_checks import EventChecks from bot_data.abc.auto_role_repository_abc import AutoRoleRepositoryABC from bot_data.abc.server_repository_abc import ServerRepositoryABC +from bot_data.model.server_config import ServerConfig from modules.auto_role.helper.auto_role_reaction_handler import AutoRoleReactionHandler class AutoRoleOnRawReactionRemoveEvent(OnRawReactionRemoveABC): def __init__( self, + config: ConfigurationABC, logger: LoggerABC, bot: DiscordBotServiceABC, servers: ServerRepositoryABC, @@ -20,6 +25,7 @@ class AutoRoleOnRawReactionRemoveEvent(OnRawReactionRemoveABC): ): OnRawReactionRemoveABC.__init__(self) + self._config = config self._logger = logger self._bot = bot self._servers = servers @@ -29,6 +35,9 @@ class AutoRoleOnRawReactionRemoveEvent(OnRawReactionRemoveABC): @EventChecks.check_is_ready() async def on_raw_reaction_remove(self, payload: RawReactionActionEvent): self._logger.debug(__name__, f"Module {type(self)} started") + server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{payload.guild_id}") + if not FeatureFlagsSettings.get_flag_from_dict(server_config.feature_flags, FeatureFlagsEnum.auto_role_module): + return await self._reaction_handler.handle(payload, "remove") diff --git a/kdb-bot/src/modules/boot_log/boot_log_on_ready_event.py b/kdb-bot/src/modules/boot_log/boot_log_on_ready_event.py index 20810163..fd42102f 100644 --- a/kdb-bot/src/modules/boot_log/boot_log_on_ready_event.py +++ b/kdb-bot/src/modules/boot_log/boot_log_on_ready_event.py @@ -8,6 +8,8 @@ from cpl_translation import TranslatePipe from discord import guild from bot_core.abc.message_service_abc import MessageServiceABC +from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum +from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings from bot_data.model.server_config import ServerConfig @@ -60,6 +62,11 @@ class BootLogOnReadyEvent(OnReadyABC): self._logger.error(__name__, f"Config {type(self).__name__}_{g.id} not found!") return + if not FeatureFlagsSettings.get_flag_from_dict( + server_config.feature_flags, FeatureFlagsEnum.boot_log_module + ): + continue + self._bot.loop.create_task( self._message_service.send_channel_message( self._bot.get_channel(server_config.login_message_channel_id), diff --git a/kdb-bot/src/modules/level/events/level_on_member_join_event.py b/kdb-bot/src/modules/level/events/level_on_member_join_event.py index 26a9dccb..6b1377e5 100644 --- a/kdb-bot/src/modules/level/events/level_on_member_join_event.py +++ b/kdb-bot/src/modules/level/events/level_on_member_join_event.py @@ -1,18 +1,29 @@ import discord +from cpl_core.configuration import ConfigurationABC from cpl_discord.events import OnMemberJoinABC +from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum +from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings from bot_core.helper.event_checks import EventChecks from bot_core.logging.message_logger import MessageLogger +from bot_data.model.server_config import ServerConfig from modules.level.service.level_service import LevelService class LevelOnMemberJoinEvent(OnMemberJoinABC): - def __init__(self, logger: MessageLogger, level: LevelService): + def __init__(self, config: ConfigurationABC, logger: MessageLogger, level: LevelService): OnMemberJoinABC.__init__(self) + self._config = config self._logger = logger self._level = level @EventChecks.check_is_ready() async def on_member_join(self, member: discord.Member): self._logger.debug(__name__, f"Module {type(self)} started") + server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{member.guild.id}") + if not FeatureFlagsSettings.get_flag_from_dict( + server_config.feature_flags, FeatureFlagsEnum.achievements_module + ): + return + await self._level.check_level(member) diff --git a/kdb-bot/src/modules/level/events/level_on_message_event.py b/kdb-bot/src/modules/level/events/level_on_message_event.py index 8bdd054c..721ab273 100644 --- a/kdb-bot/src/modules/level/events/level_on_message_event.py +++ b/kdb-bot/src/modules/level/events/level_on_message_event.py @@ -1,20 +1,31 @@ import discord +from cpl_core.configuration import ConfigurationABC from cpl_discord.events import OnMessageABC +from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum +from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings from bot_core.helper.event_checks import EventChecks from bot_core.logging.message_logger import MessageLogger +from bot_data.model.server_config import ServerConfig from modules.level.service.level_service import LevelService class LevelOnMessageEvent(OnMessageABC): - def __init__(self, logger: MessageLogger, level: LevelService): + def __init__(self, config: ConfigurationABC, logger: MessageLogger, level: LevelService): OnMessageABC.__init__(self) + self._config = config self._logger = logger self._level = level @EventChecks.check_is_ready() async def on_message(self, message: discord.Message): self._logger.debug(__name__, f"Module {type(self)} started") + server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{message.guild.id}") + if not FeatureFlagsSettings.get_flag_from_dict( + server_config.feature_flags, FeatureFlagsEnum.achievements_module + ): + return + try: await self._level.check_level(message.author) except Exception as e: diff --git a/kdb-bot/src/modules/level/events/level_on_raw_reaction_add_event.py b/kdb-bot/src/modules/level/events/level_on_raw_reaction_add_event.py index 5535b0e7..17415421 100644 --- a/kdb-bot/src/modules/level/events/level_on_raw_reaction_add_event.py +++ b/kdb-bot/src/modules/level/events/level_on_raw_reaction_add_event.py @@ -1,21 +1,27 @@ +from cpl_core.configuration import ConfigurationABC from cpl_core.logging import LoggerABC from cpl_discord.events.on_raw_reaction_add_abc import OnRawReactionAddABC from cpl_discord.service import DiscordBotServiceABC from discord import RawReactionActionEvent +from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum +from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings from bot_core.helper.event_checks import EventChecks +from bot_data.model.server_config import ServerConfig from modules.level.service.level_service import LevelService class LevelOnRawReactionAddEvent(OnRawReactionAddABC): def __init__( self, + config: ConfigurationABC, logger: LoggerABC, bot: DiscordBotServiceABC, level: LevelService, ): OnRawReactionAddABC.__init__(self) + self._config = config self._logger = logger self._bot = bot self._level = level @@ -23,6 +29,12 @@ class LevelOnRawReactionAddEvent(OnRawReactionAddABC): @EventChecks.check_is_ready() async def on_raw_reaction_add(self, payload: RawReactionActionEvent): self._logger.debug(__name__, f"Module {type(self)} started") + server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{payload.guild_id}") + if not FeatureFlagsSettings.get_flag_from_dict( + server_config.feature_flags, FeatureFlagsEnum.achievements_module + ): + return + try: self._logger.trace(__name__, f"Handle reaction {payload} for level") diff --git a/kdb-bot/src/modules/level/events/level_on_raw_reaction_remove_event.py b/kdb-bot/src/modules/level/events/level_on_raw_reaction_remove_event.py index 3e4c32d7..b2b9a1d1 100644 --- a/kdb-bot/src/modules/level/events/level_on_raw_reaction_remove_event.py +++ b/kdb-bot/src/modules/level/events/level_on_raw_reaction_remove_event.py @@ -1,21 +1,27 @@ +from cpl_core.configuration import ConfigurationABC from cpl_core.logging import LoggerABC from cpl_discord.events.on_raw_reaction_remove_abc import OnRawReactionRemoveABC from cpl_discord.service import DiscordBotServiceABC from discord import RawReactionActionEvent +from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum +from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings from bot_core.helper.event_checks import EventChecks +from bot_data.model.server_config import ServerConfig from modules.level.service.level_service import LevelService class LevelOnRawReactionRemoveEvent(OnRawReactionRemoveABC): def __init__( self, + config: ConfigurationABC, logger: LoggerABC, bot: DiscordBotServiceABC, level: LevelService, ): OnRawReactionRemoveABC.__init__(self) + self._config = config self._logger = logger self._bot = bot self._level = level @@ -23,6 +29,12 @@ class LevelOnRawReactionRemoveEvent(OnRawReactionRemoveABC): @EventChecks.check_is_ready() async def on_raw_reaction_remove(self, payload: RawReactionActionEvent): self._logger.debug(__name__, f"Module {type(self)} started") + server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{payload.guild_id}") + if not FeatureFlagsSettings.get_flag_from_dict( + server_config.feature_flags, FeatureFlagsEnum.achievements_module + ): + return + try: self._logger.trace(__name__, f"Handle reaction {payload} for level") diff --git a/kdb-bot/src/modules/level/events/level_on_voice_state_update_event.py b/kdb-bot/src/modules/level/events/level_on_voice_state_update_event.py index d5c51f95..9ab49f6d 100644 --- a/kdb-bot/src/modules/level/events/level_on_voice_state_update_event.py +++ b/kdb-bot/src/modules/level/events/level_on_voice_state_update_event.py @@ -1,14 +1,19 @@ import discord +from cpl_core.configuration import ConfigurationABC from cpl_core.logging import LoggerABC from cpl_discord.events import OnVoiceStateUpdateABC +from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum +from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings from bot_core.helper.event_checks import EventChecks +from bot_data.model.server_config import ServerConfig from modules.level.service.level_service import LevelService class LevelOnVoiceStateUpdateEvent(OnVoiceStateUpdateABC): - def __init__(self, logger: LoggerABC, level: LevelService): + def __init__(self, config: ConfigurationABC, logger: LoggerABC, level: LevelService): OnVoiceStateUpdateABC.__init__(self) + self._config = config self._logger = logger self._level = level @@ -22,4 +27,10 @@ class LevelOnVoiceStateUpdateEvent(OnVoiceStateUpdateABC): after: discord.VoiceState, ): self._logger.debug(__name__, f"Module {type(self)} started") + server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{member.guild.id}") + if not FeatureFlagsSettings.get_flag_from_dict( + server_config.feature_flags, FeatureFlagsEnum.achievements_module + ): + return + await self._level.check_level(member)