Added feature flag checks #338 #1.1.0.rc3
This commit is contained in:
parent
e283a18def
commit
aa2c80ec12
@ -11,6 +11,7 @@ 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
|
||||
from bot_data.model.technician_config import TechnicianConfig
|
||||
|
||||
|
||||
class BootLogOnReadyEvent(OnReadyABC):
|
||||
@ -21,6 +22,7 @@ class BootLogOnReadyEvent(OnReadyABC):
|
||||
bot: DiscordBotServiceABC,
|
||||
message_service: MessageServiceABC,
|
||||
translate: TranslatePipe,
|
||||
tech_config: TechnicianConfig,
|
||||
):
|
||||
OnReadyABC.__init__(self)
|
||||
self._config = config
|
||||
@ -29,11 +31,17 @@ class BootLogOnReadyEvent(OnReadyABC):
|
||||
self._bot = bot
|
||||
self._message_service = message_service
|
||||
self._t = translate
|
||||
self._tech_config = tech_config
|
||||
|
||||
self._logger.info(__name__, f"Module {type(self)} loaded")
|
||||
|
||||
async def on_ready(self):
|
||||
self._logger.debug(__name__, f"Module {type(self)} started")
|
||||
if not FeatureFlagsSettings.get_flag_from_dict(
|
||||
self._tech_config.feature_flags, FeatureFlagsEnum.boot_log_module
|
||||
):
|
||||
return
|
||||
|
||||
try:
|
||||
start_time = self._config.get_configuration("Bot_StartTime")
|
||||
init_time = round(
|
||||
|
@ -1,14 +1,18 @@
|
||||
import discord
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.database.context import DatabaseContextABC
|
||||
from cpl_discord.container import Guild
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
from discord import Permissions, Colour
|
||||
|
||||
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
|
||||
from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings
|
||||
from bot_core.logging.database_logger import DatabaseLogger
|
||||
from bot_data.abc.data_seeder_abc import DataSeederABC
|
||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||
from bot_data.model.level import Level
|
||||
from bot_data.model.server import Server
|
||||
from bot_data.model.server_config import ServerConfig
|
||||
from bot_data.service.level_repository_service import LevelRepositoryService
|
||||
from modules.level.configuration.default_level_settings import DefaultLevelSettings
|
||||
from modules.level.service.level_service import LevelService
|
||||
@ -17,6 +21,7 @@ from modules.level.service.level_service import LevelService
|
||||
class LevelSeeder(DataSeederABC):
|
||||
def __init__(
|
||||
self,
|
||||
config: ConfigurationABC,
|
||||
logger: DatabaseLogger,
|
||||
levels: DefaultLevelSettings,
|
||||
level_repo: LevelRepositoryService,
|
||||
@ -27,6 +32,7 @@ class LevelSeeder(DataSeederABC):
|
||||
):
|
||||
DataSeederABC.__init__(self)
|
||||
|
||||
self._config = config
|
||||
self._logger = logger
|
||||
self._levels = level_repo
|
||||
self._servers = servers
|
||||
@ -65,6 +71,10 @@ class LevelSeeder(DataSeederABC):
|
||||
async def seed(self):
|
||||
# create levels
|
||||
for guild in self._bot.guilds:
|
||||
server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{guild.id}")
|
||||
if not FeatureFlagsSettings.get_flag_from_dict(server_config.feature_flags, FeatureFlagsEnum.level_module):
|
||||
continue
|
||||
|
||||
created_default = False
|
||||
if guild.roles.where(lambda r: r.name == self._level_header).first_or_default() is None:
|
||||
await guild.create_role(name=self._level_header)
|
||||
|
@ -1,17 +1,29 @@
|
||||
import discord
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.logging import LoggerABC
|
||||
from cpl_discord.events import OnMemberUpdateABC
|
||||
|
||||
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
|
||||
from modules.permission.abc.permission_service_abc import PermissionServiceABC
|
||||
|
||||
|
||||
class PermissionOnMemberUpdateEvent(OnMemberUpdateABC):
|
||||
def __init__(self, logger: LoggerABC, permission_service: PermissionServiceABC):
|
||||
def __init__(self, config: ConfigurationABC, logger: LoggerABC, permission_service: PermissionServiceABC):
|
||||
OnMemberUpdateABC.__init__(self)
|
||||
self._config = config
|
||||
self._logger = logger
|
||||
self._permission_service = permission_service
|
||||
|
||||
async def on_member_update(self, before: discord.Member, after: discord.Member):
|
||||
if before.guild is not None:
|
||||
server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{before.guild.id}")
|
||||
if not FeatureFlagsSettings.get_flag_from_dict(
|
||||
server_config.feature_flags, FeatureFlagsEnum.permission_module
|
||||
):
|
||||
return
|
||||
|
||||
self._logger.debug(__name__, f"Module {type(self)} started")
|
||||
|
||||
if before.roles != after.roles:
|
||||
|
@ -1,15 +1,22 @@
|
||||
from cpl_core.logging import LoggerABC
|
||||
from cpl_discord.events import OnReadyABC
|
||||
|
||||
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
|
||||
from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings
|
||||
from bot_data.model.technician_config import TechnicianConfig
|
||||
from modules.permission.abc.permission_service_abc import PermissionServiceABC
|
||||
|
||||
|
||||
class PermissionOnReadyEvent(OnReadyABC):
|
||||
def __init__(self, logger: LoggerABC, permission_service: PermissionServiceABC):
|
||||
def __init__(self, logger: LoggerABC, permission_service: PermissionServiceABC, tech_config: TechnicianConfig):
|
||||
OnReadyABC.__init__(self)
|
||||
self._logger = logger
|
||||
self._permission_service = permission_service
|
||||
self._tech_config = tech_config
|
||||
|
||||
async def on_ready(self):
|
||||
self._logger.debug(__name__, f"Module {type(self)} started")
|
||||
if not FeatureFlagsSettings.get_flag_from_dict(
|
||||
self._tech_config.feature_flags, FeatureFlagsEnum.permission_module
|
||||
):
|
||||
return
|
||||
self._permission_service.on_ready()
|
||||
|
Loading…
Reference in New Issue
Block a user