Compare commits

..

2 Commits

Author SHA1 Message Date
6e79811bc9 Added maintenance option to technician settings #424
All checks were successful
Deploy dev on push / on-push-deploy_sh-edraft (push) Successful in 4m20s
2023-11-06 18:56:04 +01:00
e1258151de Added maintenance to db and gql #424 2023-11-06 18:02:09 +01:00
28 changed files with 185 additions and 25 deletions

View File

@ -11,6 +11,7 @@ from bot_api.api_thread import ApiThread
from bot_core.abc.task_abc import TaskABC from bot_core.abc.task_abc import TaskABC
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings
from bot_core.environment_variables import MAINTENANCE
from bot_core.service.data_integrity_service import DataIntegrityService from bot_core.service.data_integrity_service import DataIntegrityService
@ -58,7 +59,7 @@ class Application(DiscordBotApplicationABC):
return return
self._logger.info(__name__, f"Try to start {DiscordBotService.__name__}") self._logger.info(__name__, f"Try to start {DiscordBotService.__name__}")
if not self._config.get_configuration("MAINTENANCE"): if not self._config.get_configuration(MAINTENANCE):
for task in self._tasks: for task in self._tasks:
await self._bot.add_cog(task) await self._bot.add_cog(task)

View File

@ -8,6 +8,7 @@ from cpl_core.dependency_injection import ServiceCollectionABC
from cpl_core.environment import ApplicationEnvironmentABC from cpl_core.environment import ApplicationEnvironmentABC
from bot_core.configuration.bot_logging_settings import BotLoggingSettings from bot_core.configuration.bot_logging_settings import BotLoggingSettings
from bot_core.environment_variables import MAINTENANCE, MIGRATION_ONLY
class StartupSettingsExtension(StartupExtensionABC): class StartupSettingsExtension(StartupExtensionABC):
@ -20,10 +21,10 @@ class StartupSettingsExtension(StartupExtensionABC):
configuration.add_environment_variables("SDB_") configuration.add_environment_variables("SDB_")
configuration.add_environment_variables("DISCORD_") configuration.add_environment_variables("DISCORD_")
configuration.add_configuration( configuration.add_configuration(
"MAINTENANCE", configuration.get_configuration("MAINTENANCE") in [True, "true", "True"] MAINTENANCE, configuration.get_configuration(MAINTENANCE) in [True, "true", "True"]
) )
configuration.add_configuration( configuration.add_configuration(
"MIGRATION_ONLY", configuration.get_configuration("MIGRATION_ONLY") in [True, "true", "True"] MIGRATION_ONLY, configuration.get_configuration(MIGRATION_ONLY) in [True, "true", "True"]
) )
configuration.add_json_file(f"config/appsettings.json", optional=False) configuration.add_json_file(f"config/appsettings.json", optional=False)

View File

@ -75,3 +75,7 @@ class ClientUtilsABC(ABC):
@abstractmethod @abstractmethod
async def check_default_role(self, member: Union[discord.User, discord.Member]): async def check_default_role(self, member: Union[discord.User, discord.Member]):
pass pass
@abstractmethod
async def set_maintenance_mode(self, state: bool):
pass

View File

@ -6,6 +6,7 @@ from cpl_core.dependency_injection import ServiceProviderABC
from cpl_discord.service import DiscordBotServiceABC from cpl_discord.service import DiscordBotServiceABC
from discord.ext import commands from discord.ext import commands
from bot_core.environment_variables import MAINTENANCE
from bot_core.logging.task_logger import TaskLogger from bot_core.logging.task_logger import TaskLogger
@ -16,7 +17,7 @@ class TaskABC(commands.Cog):
@ServiceProviderABC.inject @ServiceProviderABC.inject
def _is_maintenance(self, config: ConfigurationABC) -> bool: def _is_maintenance(self, config: ConfigurationABC) -> bool:
return config.get_configuration("MAINTENANCE") is True return config.get_configuration(MAINTENANCE) is True
@ServiceProviderABC.inject @ServiceProviderABC.inject
async def _wait_until_ready(self, config: ConfigurationABC, logger: TaskLogger, bot: DiscordBotServiceABC): async def _wait_until_ready(self, config: ConfigurationABC, logger: TaskLogger, bot: DiscordBotServiceABC):

View File

@ -7,6 +7,7 @@ from cpl_discord.service import DiscordBotServiceABC
from cpl_translation import TranslatePipe from cpl_translation import TranslatePipe
from bot_core.abc.client_utils_abc import ClientUtilsABC from bot_core.abc.client_utils_abc import ClientUtilsABC
from bot_core.environment_variables import MAINTENANCE
class CoreExtensionOnReadyEvent(OnReadyABC): class CoreExtensionOnReadyEvent(OnReadyABC):
@ -30,8 +31,5 @@ class CoreExtensionOnReadyEvent(OnReadyABC):
async def on_ready(self): async def on_ready(self):
self._logger.debug(__name__, f"Module {type(self)} started") self._logger.debug(__name__, f"Module {type(self)} started")
if self._config.get_configuration("MAINTENANCE"): await self._client_utils.set_maintenance_mode(self._config.get_configuration(MAINTENANCE))
await self._client_utils.presence_game("common.presence.maintenance")
else:
await self._client_utils.presence_game("common.presence.running")
self._logger.trace(__name__, f"Module {type(self)} stopped") self._logger.trace(__name__, f"Module {type(self)} stopped")

View File

@ -0,0 +1,2 @@
MIGRATION_ONLY = "MIGRATION_ONLY"
MAINTENANCE = "MAINTENANCE"

View File

@ -24,12 +24,11 @@ class EventChecks:
if not result: if not result:
def empty(*args, **kwargs): def empty(*args, **kwargs):
pass return
return empty return empty
return await func(*args, **kwargs) return await func(*args, **kwargs)
# return commands.check(check_if_bot_is_ready)
check_if_bot_is_ready.__name__ = func.__name__ check_if_bot_is_ready.__name__ = func.__name__
sig = inspect.signature(func) sig = inspect.signature(func)
check_if_bot_is_ready.__signature__ = sig.replace(parameters=tuple(sig.parameters.values())[1:]) check_if_bot_is_ready.__signature__ = sig.replace(parameters=tuple(sig.parameters.values())[1:])

View File

@ -16,6 +16,7 @@ from bot_core.abc.client_utils_abc import ClientUtilsABC
from bot_core.abc.message_service_abc import MessageServiceABC from bot_core.abc.message_service_abc import MessageServiceABC
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings
from bot_core.environment_variables import MAINTENANCE
from bot_data.abc.client_repository_abc import ClientRepositoryABC from bot_data.abc.client_repository_abc import ClientRepositoryABC
from bot_data.abc.server_repository_abc import ServerRepositoryABC from bot_data.abc.server_repository_abc import ServerRepositoryABC
from bot_data.abc.user_joined_voice_channel_repository_abc import ( from bot_data.abc.user_joined_voice_channel_repository_abc import (
@ -87,7 +88,7 @@ class ClientUtilsService(ClientUtilsABC):
return client return client
async def check_if_bot_is_ready_yet(self) -> bool: async def check_if_bot_is_ready_yet(self) -> bool:
if self._config.get_configuration("MAINTENANCE"): if self._config.get_configuration(MAINTENANCE):
self._logger.warn( self._logger.warn(
__name__, __name__,
f"Bot is in maintenance mode", f"Bot is in maintenance mode",
@ -246,3 +247,10 @@ class ClientUtilsService(ClientUtilsABC):
except Exception as e: except Exception as e:
self._logger.error(__name__, f"Cannot check for default role for member {member.id}", e) self._logger.error(__name__, f"Cannot check for default role for member {member.id}", e)
async def set_maintenance_mode(self, state: bool):
self._config.add_configuration(MAINTENANCE, state)
if state:
await self.presence_game("common.presence.maintenance")
else:
await self.presence_game("common.presence.running")

View File

@ -6,6 +6,7 @@ CREATE TABLE IF NOT EXISTS `CFG_TechnicianHistory`
`WaitForShutdown` BIGINT NOT NULL DEFAULT 8, `WaitForShutdown` BIGINT NOT NULL DEFAULT 8,
`CacheMaxMessages` BIGINT NOT NULL DEFAULT 1000000, `CacheMaxMessages` BIGINT NOT NULL DEFAULT 1000000,
`MaxSteamOfferCount` BIGINT NOT NULL DEFAULT 250, `MaxSteamOfferCount` BIGINT NOT NULL DEFAULT 250,
`Maintenance` BOOLEAN DEFAULT FALSE,
`FeatureFlags` JSON NULL DEFAULT ('{}'), `FeatureFlags` JSON NULL DEFAULT ('{}'),
`Deleted` BOOL DEFAULT FALSE, `Deleted` BOOL DEFAULT FALSE,
`DateFrom` DATETIME(6) NOT NULL, `DateFrom` DATETIME(6) NOT NULL,
@ -25,6 +26,7 @@ BEGIN
`WaitForShutdown`, `WaitForShutdown`,
`CacheMaxMessages`, `CacheMaxMessages`,
`MaxSteamOfferCount`, `MaxSteamOfferCount`,
`Maintenance`,
`FeatureFlags`, `FeatureFlags`,
`DateFrom`, `DateFrom`,
`DateTo`) `DateTo`)
@ -34,6 +36,7 @@ BEGIN
OLD.WaitForShutdown, OLD.WaitForShutdown,
OLD.CacheMaxMessages, OLD.CacheMaxMessages,
OLD.MaxSteamOfferCount, OLD.MaxSteamOfferCount,
OLD.Maintenance,
OLD.FeatureFlags, OLD.FeatureFlags,
OLD.LastModifiedAt, OLD.LastModifiedAt,
CURRENT_TIMESTAMP(6)); CURRENT_TIMESTAMP(6));
@ -52,6 +55,7 @@ BEGIN
`WaitForShutdown`, `WaitForShutdown`,
`CacheMaxMessages`, `CacheMaxMessages`,
`MaxSteamOfferCount`, `MaxSteamOfferCount`,
`Maintenance`,
`FeatureFlags`, `FeatureFlags`,
`Deleted`, `Deleted`,
`DateFrom`, `DateFrom`,
@ -62,6 +66,7 @@ BEGIN
OLD.WaitForShutdown, OLD.WaitForShutdown,
OLD.CacheMaxMessages, OLD.CacheMaxMessages,
OLD.MaxSteamOfferCount, OLD.MaxSteamOfferCount,
OLD.Maintenance,
OLD.FeatureFlags, OLD.FeatureFlags,
TRUE, TRUE,
OLD.LastModifiedAt, OLD.LastModifiedAt,

View File

@ -0,0 +1,51 @@
from bot_core.logging.database_logger import DatabaseLogger
from bot_data.abc.migration_abc import MigrationABC
from bot_data.db_context import DBContext
class MaintenanceModeMigration(MigrationABC):
name = "1.2.0_MaintenanceModeMigration"
def __init__(self, logger: DatabaseLogger, db: DBContext):
MigrationABC.__init__(self)
self._logger = logger
self._db = db
self._cursor = db.cursor
def upgrade(self):
self._logger.debug(__name__, "Running upgrade")
self._cursor.execute(
str(
f"""
ALTER TABLE CFG_Technician
ADD Maintenance BOOLEAN DEFAULT FALSE AFTER MaxSteamOfferCount;
"""
)
)
self._cursor.execute(
str(
f"""
ALTER TABLE CFG_TechnicianHistory
ADD Maintenance BOOLEAN DEFAULT FALSE AFTER MaxSteamOfferCount;
"""
)
)
self._exec(__file__, "config/technician.sql")
def downgrade(self):
self._cursor.execute(
str(
f"""
ALTER TABLE CFG_Technician DROP COLUMN Maintenance;
"""
)
)
self._cursor.execute(
str(
f"""
ALTER TABLE CFG_TechnicianHistory DROP COLUMN Maintenance;
"""
)
)

View File

@ -16,6 +16,7 @@ class TechnicianConfig(TableABC, ConfigurationModelABC):
wait_for_shutdown: int, wait_for_shutdown: int,
cache_max_messages: int, cache_max_messages: int,
max_steam_offer_count: int, max_steam_offer_count: int,
maintenance: bool,
feature_flags: dict[FeatureFlagsEnum], feature_flags: dict[FeatureFlagsEnum],
technician_ids: List[int], technician_ids: List[int],
ping_urls: List[str], ping_urls: List[str],
@ -29,6 +30,8 @@ class TechnicianConfig(TableABC, ConfigurationModelABC):
self._wait_for_shutdown = wait_for_shutdown self._wait_for_shutdown = wait_for_shutdown
self._cache_max_messages = cache_max_messages self._cache_max_messages = cache_max_messages
self._max_steam_offer_count = max_steam_offer_count self._max_steam_offer_count = max_steam_offer_count
self._maintenance = maintenance
self._feature_flags = feature_flags self._feature_flags = feature_flags
self._technician_ids = technician_ids self._technician_ids = technician_ids
self._ping_urls = ping_urls self._ping_urls = ping_urls
@ -105,6 +108,14 @@ class TechnicianConfig(TableABC, ConfigurationModelABC):
def ping_urls(self, value: List[str]): def ping_urls(self, value: List[str]):
self._ping_urls = value self._ping_urls = value
@property
def maintenance(self) -> bool:
return self._maintenance
@maintenance.setter
def maintenance(self, value: bool):
self._maintenance = value
@staticmethod @staticmethod
def get_select_all_string() -> str: def get_select_all_string() -> str:
return str( return str(

View File

@ -47,11 +47,12 @@ class TechnicianConfigRepositoryService(TechnicianConfigRepositoryABC):
result[3], result[3],
result[4], result[4],
result[5], result[5],
json.loads(result[6]), bool(result[6]),
json.loads(result[7]),
self._get_technician_ids(), self._get_technician_ids(),
self._get_technician_ping_urls(), self._get_technician_ping_urls(),
result[7],
result[8], result[8],
result[9],
id=result[0], id=result[0],
) )

View File

@ -20,6 +20,7 @@ from bot_data.migration.fix_updates_migration import FixUpdatesMigration
from bot_data.migration.fix_user_history_migration import FixUserHistoryMigration from bot_data.migration.fix_user_history_migration import FixUserHistoryMigration
from bot_data.migration.initial_migration import InitialMigration from bot_data.migration.initial_migration import InitialMigration
from bot_data.migration.level_migration import LevelMigration from bot_data.migration.level_migration import LevelMigration
from bot_data.migration.maintenance_mode_migration import MaintenanceModeMigration
from bot_data.migration.max_steam_offer_count_migration import MaxSteamOfferCountMigration from bot_data.migration.max_steam_offer_count_migration import MaxSteamOfferCountMigration
from bot_data.migration.remove_stats_migration import RemoveStatsMigration from bot_data.migration.remove_stats_migration import RemoveStatsMigration
from bot_data.migration.short_role_name_migration import ShortRoleNameMigration from bot_data.migration.short_role_name_migration import ShortRoleNameMigration
@ -70,3 +71,4 @@ class StartupMigrationExtension(StartupExtensionABC):
services.add_transient(MigrationABC, BirthdayMigration) # 10.10.2023 #401 - 1.2.0 services.add_transient(MigrationABC, BirthdayMigration) # 10.10.2023 #401 - 1.2.0
services.add_transient(MigrationABC, SteamSpecialOfferMigration) # 10.10.2023 #188 - 1.2.0 services.add_transient(MigrationABC, SteamSpecialOfferMigration) # 10.10.2023 #188 - 1.2.0
services.add_transient(MigrationABC, MaxSteamOfferCountMigration) # 04.11.2023 #188 - 1.2.0 services.add_transient(MigrationABC, MaxSteamOfferCountMigration) # 04.11.2023 #188 - 1.2.0
services.add_transient(MigrationABC, MaintenanceModeMigration) # 06.11.2023 #424 - 1.2.0

View File

@ -11,6 +11,7 @@ from bot_api.exception.service_error_code_enum import ServiceErrorCode
from bot_api.exception.service_exception import ServiceException from bot_api.exception.service_exception import ServiceException
from bot_api.route.route import Route from bot_api.route.route import Route
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
from bot_core.environment_variables import MAINTENANCE
from bot_data.model.achievement import Achievement from bot_data.model.achievement import Achievement
from bot_data.model.auth_role_enum import AuthRoleEnum from bot_data.model.auth_role_enum import AuthRoleEnum
from bot_data.model.auth_user import AuthUser from bot_data.model.auth_user import AuthUser
@ -93,7 +94,7 @@ class QueryABC(ObjectType):
if permissions.is_member_technician(guild.get_member(u.discord_id)): if permissions.is_member_technician(guild.get_member(u.discord_id)):
return True return True
if config.get_configuration("MAINTENANCE"): if config.get_configuration(MAINTENANCE):
return False return False
access = False access = False
@ -242,11 +243,11 @@ class QueryABC(ObjectType):
match permission: match permission:
case UserRoleEnum.moderator: case UserRoleEnum.moderator:
can_edit = permissions.is_member_moderator can_edit = permissions.is_member_moderator
if config.get_configuration("MAINTENANCE"): if config.get_configuration(MAINTENANCE):
can_edit = lambda x: False can_edit = lambda x: False
case UserRoleEnum.admin: case UserRoleEnum.admin:
can_edit = permissions.is_member_admin can_edit = permissions.is_member_admin
if config.get_configuration("MAINTENANCE"): if config.get_configuration(MAINTENANCE):
can_edit = lambda x: False can_edit = lambda x: False
case UserRoleEnum.technician: case UserRoleEnum.technician:
can_edit = permissions.is_member_technician can_edit = permissions.is_member_technician

View File

@ -5,6 +5,7 @@ type TechnicianConfig implements TableWithHistoryQuery {
waitForShutdown: Int waitForShutdown: Int
cacheMaxMessages: Int cacheMaxMessages: Int
maxSteamOfferCount: Int maxSteamOfferCount: Int
maintenance: Boolean
featureFlagCount: Int featureFlagCount: Int
featureFlags: [FeatureFlag] featureFlags: [FeatureFlag]
pingURLs: [String] pingURLs: [String]
@ -25,6 +26,7 @@ type TechnicianConfigHistory implements HistoryTableQuery {
waitForShutdown: Int waitForShutdown: Int
cacheMaxMessages: Int cacheMaxMessages: Int
maxSteamOfferCount: Int maxSteamOfferCount: Int
maintenance: Boolean
featureFlagCount: Int featureFlagCount: Int
featureFlags: [FeatureFlag] featureFlags: [FeatureFlag]
@ -62,6 +64,7 @@ input TechnicianConfigInput {
waitForShutdown: Int waitForShutdown: Int
cacheMaxMessages: Int cacheMaxMessages: Int
maxSteamOfferCount: Int maxSteamOfferCount: Int
maintenance: Boolean
featureFlags: [FeatureFlagInput] featureFlags: [FeatureFlagInput]
pingURLs: [String] pingURLs: [String]
technicianIds: [String] technicianIds: [String]

View File

@ -1,9 +1,12 @@
from cpl_core.configuration import ConfigurationABC
from cpl_core.database.context import DatabaseContextABC from cpl_core.database.context import DatabaseContextABC
from cpl_discord.service import DiscordBotServiceABC from cpl_discord.service import DiscordBotServiceABC
from cpl_query.extension import List from cpl_query.extension import List
from bot_api.logging.api_logger import ApiLogger from bot_api.logging.api_logger import ApiLogger
from bot_api.route.route import Route from bot_api.route.route import Route
from bot_core.abc.client_utils_abc import ClientUtilsABC
from bot_core.environment_variables import MAINTENANCE
from bot_core.service.config_service import ConfigService from bot_core.service.config_service import ConfigService
from bot_data.abc.server_repository_abc import ServerRepositoryABC from bot_data.abc.server_repository_abc import ServerRepositoryABC
from bot_data.abc.technician_config_repository_abc import TechnicianConfigRepositoryABC from bot_data.abc.technician_config_repository_abc import TechnicianConfigRepositoryABC
@ -18,6 +21,7 @@ from bot_graphql.abc.query_abc import QueryABC
class TechnicianConfigMutation(QueryABC): class TechnicianConfigMutation(QueryABC):
def __init__( def __init__(
self, self,
config: ConfigurationABC,
logger: ApiLogger, logger: ApiLogger,
bot: DiscordBotServiceABC, bot: DiscordBotServiceABC,
servers: ServerRepositoryABC, servers: ServerRepositoryABC,
@ -25,9 +29,11 @@ class TechnicianConfigMutation(QueryABC):
db: DatabaseContextABC, db: DatabaseContextABC,
config_service: ConfigService, config_service: ConfigService,
tech_seeder: TechnicianConfigSeeder, tech_seeder: TechnicianConfigSeeder,
client_utils: ClientUtilsABC,
): ):
QueryABC.__init__(self, "TechnicianConfigMutation") QueryABC.__init__(self, "TechnicianConfigMutation")
self._config = config
self._logger = logger self._logger = logger
self._bot = bot self._bot = bot
self._servers = servers self._servers = servers
@ -35,6 +41,7 @@ class TechnicianConfigMutation(QueryABC):
self._db = db self._db = db
self._config_service = config_service self._config_service = config_service
self._tech_seeder = tech_seeder self._tech_seeder = tech_seeder
self._client_utils = client_utils
self.set_field("updateTechnicianConfig", self.resolve_update_technician_config) self.set_field("updateTechnicianConfig", self.resolve_update_technician_config)
@ -62,6 +69,9 @@ class TechnicianConfigMutation(QueryABC):
technician_config.max_steam_offer_count = ( technician_config.max_steam_offer_count = (
input["maxSteamOfferCount"] if "maxSteamOfferCount" in input else technician_config.max_steam_offer_count input["maxSteamOfferCount"] if "maxSteamOfferCount" in input else technician_config.max_steam_offer_count
) )
technician_config.maintenance = (
input["maintenance"] if "maintenance" in input else technician_config.maintenance
)
old_feature_flags = technician_config.feature_flags old_feature_flags = technician_config.feature_flags
technician_config.feature_flags = ( technician_config.feature_flags = (
dict( dict(
@ -94,6 +104,9 @@ class TechnicianConfigMutation(QueryABC):
self._update_technician_ids(technician_config) self._update_technician_ids(technician_config)
self._db.save_changes() self._db.save_changes()
if technician_config.maintenance != self._config.get_configuration(MAINTENANCE):
self._bot.loop.create_task(self._client_utils.set_maintenance_mode(technician_config.maintenance))
self._bot.loop.create_task(self._config_service.reload_technician_config()) self._bot.loop.create_task(self._config_service.reload_technician_config())
return technician_config return technician_config

View File

@ -15,6 +15,7 @@ class TechnicianConfigHistoryQuery(HistoryQueryABC):
self.set_field("waitForShutdown", lambda config, *_: config.wait_for_shutdown) self.set_field("waitForShutdown", lambda config, *_: config.wait_for_shutdown)
self.set_field("cacheMaxMessages", lambda config, *_: config.cache_max_messages) self.set_field("cacheMaxMessages", lambda config, *_: config.cache_max_messages)
self.set_field("maxSteamOfferCount", lambda config, *_: config.max_steam_offer_count) self.set_field("maxSteamOfferCount", lambda config, *_: config.max_steam_offer_count)
self.set_field("maintenance", lambda config, *_: config.maintenance)
self.add_collection( self.add_collection(
"featureFlag", "featureFlag",
lambda config, *_: List( lambda config, *_: List(

View File

@ -28,6 +28,7 @@ class TechnicianConfigQuery(DataQueryWithHistoryABC):
self.set_field("waitForShutdown", lambda config, *_: config.wait_for_shutdown) self.set_field("waitForShutdown", lambda config, *_: config.wait_for_shutdown)
self.set_field("cacheMaxMessages", lambda config, *_: config.cache_max_messages) self.set_field("cacheMaxMessages", lambda config, *_: config.cache_max_messages)
self.set_field("maxSteamOfferCount", lambda config, *_: config.max_steam_offer_count) self.set_field("maxSteamOfferCount", lambda config, *_: config.max_steam_offer_count)
self.set_field("maintenance", lambda config, *_: config.maintenance)
self.add_collection( self.add_collection(
"featureFlag", "featureFlag",
lambda config, *_: List( lambda config, *_: List(

View File

@ -8,6 +8,7 @@ from cpl_core.logging import LoggerABC
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings
from bot_core.environment_variables import MIGRATION_ONLY
from bot_core.logging.database_logger import DatabaseLogger from bot_core.logging.database_logger import DatabaseLogger
from bot_data.service.migration_service import MigrationService from bot_data.service.migration_service import MigrationService
@ -25,6 +26,6 @@ class DatabaseExtension(ApplicationExtensionABC):
config.add_configuration("Database_StartTime", str(datetime.now())) config.add_configuration("Database_StartTime", str(datetime.now()))
migrations: MigrationService = services.get_service(MigrationService) migrations: MigrationService = services.get_service(MigrationService)
migrations.migrate() migrations.migrate()
if config.get_configuration("MIGRATION_ONLY"): if config.get_configuration(MIGRATION_ONLY):
logger.warn(__name__, "Migrations finished. Stopping application...") logger.warn(__name__, "Migrations finished. Stopping application...")
sys.exit() sys.exit()

View File

@ -8,6 +8,7 @@ export interface TechnicianConfig extends DataWithHistory {
waitForShutdown?: number; waitForShutdown?: number;
cacheMaxMessages?: number; cacheMaxMessages?: number;
maxSteamOfferCount?: number; maxSteamOfferCount?: number;
maintenance?: boolean;
featureFlags: FeatureFlag[]; featureFlags: FeatureFlag[];
pingURLs: string[]; pingURLs: string[];
technicianIds: string[]; technicianIds: string[];

View File

@ -216,7 +216,7 @@ export class Mutations {
`; `;
static updateTechnicianConfig = ` static updateTechnicianConfig = `
mutation updateTechnicianConfig($id: ID, $helpCommandReferenceUrl: String, $waitForRestart: Int, $waitForShutdown: Int, $cacheMaxMessages: Int, $maxSteamOfferCount: Int, $featureFlags: [FeatureFlagInput], $pingURLs: [String], $technicianIds: [String]) { mutation updateTechnicianConfig($id: ID, $helpCommandReferenceUrl: String, $waitForRestart: Int, $waitForShutdown: Int, $cacheMaxMessages: Int, $maxSteamOfferCount: Int, $maintenance: Boolean, $featureFlags: [FeatureFlagInput], $pingURLs: [String], $technicianIds: [String]) {
technicianConfig { technicianConfig {
updateTechnicianConfig(input: { updateTechnicianConfig(input: {
id: $id, id: $id,
@ -225,6 +225,7 @@ export class Mutations {
waitForShutdown: $waitForShutdown, waitForShutdown: $waitForShutdown,
cacheMaxMessages: $cacheMaxMessages, cacheMaxMessages: $cacheMaxMessages,
maxSteamOfferCount: $maxSteamOfferCount, maxSteamOfferCount: $maxSteamOfferCount,
maintenance: $maintenance,
featureFlags: $featureFlags, featureFlags: $featureFlags,
pingURLs: $pingURLs, pingURLs: $pingURLs,
technicianIds: $technicianIds technicianIds: $technicianIds
@ -235,6 +236,7 @@ export class Mutations {
waitForShutdown waitForShutdown
cacheMaxMessages cacheMaxMessages
maxSteamOfferCount maxSteamOfferCount
maintenance
featureFlags { featureFlags {
key key
value value

View File

@ -511,6 +511,7 @@ export class Queries {
waitForShutdown waitForShutdown
cacheMaxMessages cacheMaxMessages
maxSteamOfferCount maxSteamOfferCount
maintenance
featureFlags { featureFlags {
key key
value value

View File

@ -109,7 +109,8 @@
<form [formGroup]="testMailForm" class="content-column"> <form [formGroup]="testMailForm" class="content-column">
<div class="content-data-name"> <div class="content-data-name">
<div class="input-field content-input-field"> <div class="input-field content-input-field">
<input type="email" pInputText formControlName="mail" placeholder="{{'common.email' | translate}}" autocomplete="email"> <input type="email" pInputText formControlName="mail" placeholder="{{'common.email' | translate}}"
autocomplete="email">
</div> </div>
</div> </div>
@ -136,7 +137,8 @@
<div class="content-column"> <div class="content-column">
<div class="content-data-name">{{'admin.settings.bot.help_url' | translate}}:</div> <div class="content-data-name">{{'admin.settings.bot.help_url' | translate}}:</div>
<div class="content-data-value"> <div class="content-data-value">
<input type="text" pInputText [(ngModel)]="config.helpCommandReferenceUrl" placeholder="{{'admin.settings.bot.help_url' | translate}}"> <input type="text" pInputText [(ngModel)]="config.helpCommandReferenceUrl"
placeholder="{{'admin.settings.bot.help_url' | translate}}">
</div> </div>
</div> </div>
</div> </div>
@ -145,7 +147,8 @@
<div class="content-column"> <div class="content-column">
<div class="content-data-name">{{'admin.settings.bot.wait_for_restart' | translate}}:</div> <div class="content-data-name">{{'admin.settings.bot.wait_for_restart' | translate}}:</div>
<div class="content-data-value"> <div class="content-data-value">
<input type="number" pInputText [(ngModel)]="config.waitForRestart" placeholder="{{'admin.settings.bot.wait_for_restart' | translate}}"> <input type="number" pInputText [(ngModel)]="config.waitForRestart"
placeholder="{{'admin.settings.bot.wait_for_restart' | translate}}">
</div> </div>
</div> </div>
</div> </div>
@ -154,7 +157,8 @@
<div class="content-column"> <div class="content-column">
<div class="content-data-name">{{'admin.settings.bot.wait_for_shutdown' | translate}}:</div> <div class="content-data-name">{{'admin.settings.bot.wait_for_shutdown' | translate}}:</div>
<div class="content-data-value"> <div class="content-data-value">
<input type="number" pInputText [(ngModel)]="config.waitForShutdown" placeholder="{{'admin.settings.bot.wait_for_shutdown' | translate}}"> <input type="number" pInputText [(ngModel)]="config.waitForShutdown"
placeholder="{{'admin.settings.bot.wait_for_shutdown' | translate}}">
</div> </div>
</div> </div>
</div> </div>
@ -163,7 +167,8 @@
<div class="content-column"> <div class="content-column">
<div class="content-data-name">{{'admin.settings.bot.cache_max_messages' | translate}}:</div> <div class="content-data-name">{{'admin.settings.bot.cache_max_messages' | translate}}:</div>
<div class="content-data-value"> <div class="content-data-value">
<input type="number" pInputText [(ngModel)]="config.cacheMaxMessages" placeholder="{{'admin.settings.bot.cache_max_messages' | translate}}"> <input type="number" pInputText [(ngModel)]="config.cacheMaxMessages"
placeholder="{{'admin.settings.bot.cache_max_messages' | translate}}">
</div> </div>
</div> </div>
</div> </div>
@ -172,14 +177,23 @@
<div class="content-column"> <div class="content-column">
<div class="content-data-name">{{'admin.settings.bot.max_steam_offer_count' | translate}}:</div> <div class="content-data-name">{{'admin.settings.bot.max_steam_offer_count' | translate}}:</div>
<div class="content-data-value"> <div class="content-data-value">
<input type="number" pInputText [(ngModel)]="config.maxSteamOfferCount" placeholder="{{'admin.settings.bot.max_steam_offer_count' | translate}}"> <input type="number" pInputText [(ngModel)]="config.maxSteamOfferCount"
placeholder="{{'admin.settings.bot.max_steam_offer_count' | translate}}">
</div> </div>
</div> </div>
</div> </div>
<div class="content-row">
<div class="content-column">
<div class="content-data-name">{{'view.server.config.bot.maintenance' | translate}}:</div>
<p-selectButton class="table-edit-input" [options]="stateOptions" [(ngModel)]="config.maintenance"></p-selectButton>
</div>
</div>
<div class="content-divider"></div> <div class="content-divider"></div>
<app-config-list translationKey="admin.settings.bot.ping_urls" [(data)]="config.pingURLs"></app-config-list> <app-config-list translationKey="admin.settings.bot.ping_urls" [(data)]="config.pingURLs"></app-config-list>
<app-config-list translationKey="admin.settings.bot.technician_ids" [options]="possibleTechnicians" optionLabel="name" optionValue="id" <app-config-list translationKey="admin.settings.bot.technician_ids" [options]="possibleTechnicians"
optionLabel="name" optionValue="id"
[(data)]="config.technicianIds"></app-config-list> [(data)]="config.technicianIds"></app-config-list>
<app-feature-flag-list [(data)]="config.featureFlags"></app-feature-flag-list> <app-feature-flag-list [(data)]="config.featureFlags"></app-feature-flag-list>

View File

@ -56,6 +56,10 @@ export class SettingsComponent implements OnInit {
}; };
possibleTechnicians?: DiscordUser[]; possibleTechnicians?: DiscordUser[];
stateOptions: any[] = [
{ label: this.translate.instant("common.state.off"), value: false },
{ label: this.translate.instant("common.state.on"), value: true }
];
constructor( constructor(
private dataService: DataService, private dataService: DataService,
@ -157,6 +161,7 @@ export class SettingsComponent implements OnInit {
waitForShutdown: this.config.waitForShutdown, waitForShutdown: this.config.waitForShutdown,
cacheMaxMessages: this.config.cacheMaxMessages, cacheMaxMessages: this.config.cacheMaxMessages,
maxSteamOfferCount: this.config.maxSteamOfferCount, maxSteamOfferCount: this.config.maxSteamOfferCount,
maintenance: this.config.maintenance,
featureFlags: this.config.featureFlags, featureFlags: this.config.featureFlags,
pingURLs: this.config.pingURLs, pingURLs: this.config.pingURLs,
technicianIds: this.config.technicianIds technicianIds: this.config.technicianIds

View File

@ -35,6 +35,7 @@ import { InputSwitchModule } from "primeng/inputswitch";
import { CalendarModule } from "primeng/calendar"; import { CalendarModule } from "primeng/calendar";
import { DataImportAndExportComponent } from './components/data-import-and-export/data-import-and-export.component'; import { DataImportAndExportComponent } from './components/data-import-and-export/data-import-and-export.component';
import { FileUploadModule } from "primeng/fileupload"; import { FileUploadModule } from "primeng/fileupload";
import { SelectButtonModule } from "primeng/selectbutton";
const PrimeNGModules = [ const PrimeNGModules = [
@ -64,6 +65,7 @@ const PrimeNGModules = [
InputSwitchModule, InputSwitchModule,
CalendarModule, CalendarModule,
FileUploadModule, FileUploadModule,
SelectButtonModule,
] ]
@NgModule({ @NgModule({

View File

@ -200,6 +200,10 @@
"role": "Rolle", "role": "Rolle",
"rule_count": "Regeln", "rule_count": "Regeln",
"save": "Speichern", "save": "Speichern",
"state": {
"off": "Aus",
"on": "Ein"
},
"user_warnings": "Verwarnungen", "user_warnings": "Verwarnungen",
"users": "Benutzer", "users": "Benutzer",
"value": "Wert", "value": "Wert",
@ -433,6 +437,7 @@
"header": "Bot Konfiguration", "header": "Bot Konfiguration",
"help_voice_channel_id": "Sprachkanal für Hilfsbenachrichtung", "help_voice_channel_id": "Sprachkanal für Hilfsbenachrichtung",
"login_message_channel_id": "Kanal für die Nachricht vom Bot nach Start", "login_message_channel_id": "Kanal für die Nachricht vom Bot nach Start",
"maintenance": "Wartungsmodus",
"max_message_xp_per_hour": "Maximale XP pro Stunde durch Nachrichten", "max_message_xp_per_hour": "Maximale XP pro Stunde durch Nachrichten",
"max_voice_state_hours": "Maximale Stunden für eine ontime nach Bot neustart", "max_voice_state_hours": "Maximale Stunden für eine ontime nach Bot neustart",
"message_delete_timer": "Zeit bis zum löschen einer Botnachricht in sekunden", "message_delete_timer": "Zeit bis zum löschen einer Botnachricht in sekunden",

View File

@ -200,6 +200,10 @@
"role": "Role", "role": "Role",
"rule_count": "Rules", "rule_count": "Rules",
"save": "Save", "save": "Save",
"state": {
"off": "Off",
"on": "On"
},
"user_warnings": "User warnings", "user_warnings": "User warnings",
"users": "User", "users": "User",
"value": "Value", "value": "Value",
@ -433,6 +437,7 @@
"header": "Bot configuration", "header": "Bot configuration",
"help_voice_channel_id": "Voicechannel für help notifications", "help_voice_channel_id": "Voicechannel für help notifications",
"login_message_channel_id": "Channel for bot message after start", "login_message_channel_id": "Channel for bot message after start",
"maintenance": "Maintenance mode",
"max_message_xp_per_hour": "Max xp per hour with message", "max_message_xp_per_hour": "Max xp per hour with message",
"max_voice_state_hours": "Max ontime hours after bot restart", "max_voice_state_hours": "Max ontime hours after bot restart",
"message_delete_timer": "Time to wait before delete bot messages", "message_delete_timer": "Time to wait before delete bot messages",

View File

@ -626,6 +626,27 @@
} }
} }
.p-selectbutton {
.p-highlight {
background-color: $primaryHeaderColor !important;
}
.p-button {
border: 1px solid $primaryHeaderColor !important;
&:hover {
background-color: $secondaryHeaderColor !important;
border: 1px solid $secondaryHeaderColor !important;
}
&:focus {
border-color: $primaryHeaderColor !important;
box-shadow: none !important;
}
}
}
.p-multiselect { .p-multiselect {
background-color: $primaryBackgroundColor !important; background-color: $primaryBackgroundColor !important;
color: $primaryTextColor !important; color: $primaryTextColor !important;