Added feature flag check for scheduled events #455
This commit is contained in:
parent
39299eb11b
commit
dfdf0555d7
@ -1,22 +1,34 @@
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_discord.command import DiscordCommandABC
|
||||
from cpl_translation import TranslatePipe
|
||||
from discord.ext import commands
|
||||
from discord.ext.commands import Context
|
||||
|
||||
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_core.service.message_service import MessageService
|
||||
from bot_data.model.server_config import ServerConfig
|
||||
from modules.base.service.event_service import EventService
|
||||
|
||||
|
||||
class ScheduledEventsCommand(DiscordCommandABC):
|
||||
def __init__(
|
||||
self,
|
||||
config: ConfigurationABC,
|
||||
logger: CommandLogger,
|
||||
events: EventService,
|
||||
message_service: MessageService,
|
||||
t: TranslatePipe,
|
||||
):
|
||||
DiscordCommandABC.__init__(self)
|
||||
|
||||
self._config = config
|
||||
self._logger = logger
|
||||
self._events = events
|
||||
self._message_service = message_service
|
||||
self._t = t
|
||||
|
||||
self._logger.trace(__name__, f"Loaded command service: {type(self).__name__}")
|
||||
|
||||
@ -30,6 +42,12 @@ class ScheduledEventsCommand(DiscordCommandABC):
|
||||
@CommandChecks.check_is_ready()
|
||||
@CommandChecks.check_is_member_moderator()
|
||||
async def reload(self, ctx: Context):
|
||||
settings: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild.id}")
|
||||
if not FeatureFlagsSettings.get_flag_from_dict(settings.feature_flags, FeatureFlagsEnum.scheduled_events):
|
||||
self._logger.debug(__name__, f"Skipping scheduled event check for {ctx.guild.id}. Feature is disabled.")
|
||||
await self._message_service.send_ctx_msg(ctx, self._t.transform("common.feature_not_activated"))
|
||||
return
|
||||
|
||||
self._logger.debug(__name__, "Running scheduled-events reload")
|
||||
try:
|
||||
await self._events.check_and_create_scheduled_events(ctx.guild)
|
||||
|
@ -5,9 +5,12 @@ from cpl_translation import TranslatePipe
|
||||
from discord.ext import tasks
|
||||
|
||||
from bot_core.abc.task_abc import TaskABC
|
||||
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
|
||||
from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings
|
||||
from bot_core.logging.task_logger import TaskLogger
|
||||
from bot_core.service.message_service import MessageService
|
||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||
from bot_data.model.server_config import ServerConfig
|
||||
from modules.base.service.event_service import EventService
|
||||
|
||||
|
||||
@ -42,6 +45,13 @@ class ScheduledEventsWatcher(TaskABC):
|
||||
self._logger.info(__name__, "Watching scheduled events")
|
||||
try:
|
||||
for guild in self._bot.guilds:
|
||||
settings: ServerConfig = self._config.get_configuration(f"ServerConfig_{guild.id}")
|
||||
if not FeatureFlagsSettings.get_flag_from_dict(
|
||||
settings.feature_flags, FeatureFlagsEnum.scheduled_events
|
||||
):
|
||||
self._logger.debug(__name__, f"Skipping scheduled event check for {guild.id}. Feature is disabled.")
|
||||
continue
|
||||
|
||||
await self._events.check_and_create_scheduled_events(guild)
|
||||
except Exception as e:
|
||||
self._logger.error(__name__, f"Watching scheduled events failed", e)
|
||||
|
Loading…
Reference in New Issue
Block a user