diff --git a/bot/src/bot/startup_settings_extension.py b/bot/src/bot/startup_settings_extension.py index c792b077..c3db171a 100644 --- a/bot/src/bot/startup_settings_extension.py +++ b/bot/src/bot/startup_settings_extension.py @@ -8,7 +8,7 @@ from cpl_core.dependency_injection import ServiceCollectionABC from cpl_core.environment import ApplicationEnvironmentABC from bot_core.configuration.bot_logging_settings import BotLoggingSettings -from bot_core.environment_variables import MAINTENANCE +from bot_core.environment_variables import MAINTENANCE, MIGRATION_ONLY class StartupSettingsExtension(StartupExtensionABC): @@ -24,7 +24,7 @@ class StartupSettingsExtension(StartupExtensionABC): MAINTENANCE, configuration.get_configuration(MAINTENANCE) in [True, "true", "True"] ) 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) diff --git a/bot/src/bot_core/abc/client_utils_abc.py b/bot/src/bot_core/abc/client_utils_abc.py index fdcf5118..66e25500 100644 --- a/bot/src/bot_core/abc/client_utils_abc.py +++ b/bot/src/bot_core/abc/client_utils_abc.py @@ -75,3 +75,7 @@ class ClientUtilsABC(ABC): @abstractmethod async def check_default_role(self, member: Union[discord.User, discord.Member]): pass + + @abstractmethod + async def set_maintenance_mode(self, state: bool): + pass diff --git a/bot/src/bot_core/core_extension/core_extension_on_ready_event.py b/bot/src/bot_core/core_extension/core_extension_on_ready_event.py index 1fa482a7..277cf566 100644 --- a/bot/src/bot_core/core_extension/core_extension_on_ready_event.py +++ b/bot/src/bot_core/core_extension/core_extension_on_ready_event.py @@ -31,8 +31,5 @@ class CoreExtensionOnReadyEvent(OnReadyABC): async def on_ready(self): self._logger.debug(__name__, f"Module {type(self)} started") - if self._config.get_configuration(MAINTENANCE): - await self._client_utils.presence_game("common.presence.maintenance") - else: - await self._client_utils.presence_game("common.presence.running") + await self._client_utils.set_maintenance_mode(self._config.get_configuration(MAINTENANCE)) self._logger.trace(__name__, f"Module {type(self)} stopped") diff --git a/bot/src/bot_core/environment_variables.py b/bot/src/bot_core/environment_variables.py index 2cd1cadc..74a9dc01 100644 --- a/bot/src/bot_core/environment_variables.py +++ b/bot/src/bot_core/environment_variables.py @@ -1 +1,2 @@ +MIGRATION_ONLY = "MIGRATION_ONLY" MAINTENANCE = "MAINTENANCE" diff --git a/bot/src/bot_core/service/client_utils_service.py b/bot/src/bot_core/service/client_utils_service.py index 26fe6b13..e316bf03 100644 --- a/bot/src/bot_core/service/client_utils_service.py +++ b/bot/src/bot_core/service/client_utils_service.py @@ -247,3 +247,10 @@ class ClientUtilsService(ClientUtilsABC): except Exception as 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") diff --git a/bot/src/bot_data/service/technician_config_repository_service.py b/bot/src/bot_data/service/technician_config_repository_service.py index eb9293f7..f5c27306 100644 --- a/bot/src/bot_data/service/technician_config_repository_service.py +++ b/bot/src/bot_data/service/technician_config_repository_service.py @@ -47,11 +47,12 @@ class TechnicianConfigRepositoryService(TechnicianConfigRepositoryABC): result[3], result[4], result[5], - json.loads(result[6]), + bool(result[6]), + json.loads(result[7]), self._get_technician_ids(), self._get_technician_ping_urls(), - result[7], result[8], + result[9], id=result[0], ) diff --git a/bot/src/bot_data/startup_migration_extension.py b/bot/src/bot_data/startup_migration_extension.py index 8780d94f..14a90938 100644 --- a/bot/src/bot_data/startup_migration_extension.py +++ b/bot/src/bot_data/startup_migration_extension.py @@ -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.initial_migration import InitialMigration 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.remove_stats_migration import RemoveStatsMigration 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, SteamSpecialOfferMigration) # 10.10.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 diff --git a/bot/src/bot_graphql/mutations/technician_config_mutation.py b/bot/src/bot_graphql/mutations/technician_config_mutation.py index 543a87b4..67091955 100644 --- a/bot/src/bot_graphql/mutations/technician_config_mutation.py +++ b/bot/src/bot_graphql/mutations/technician_config_mutation.py @@ -1,9 +1,12 @@ +from cpl_core.configuration import ConfigurationABC from cpl_core.database.context import DatabaseContextABC from cpl_discord.service import DiscordBotServiceABC from cpl_query.extension import List from bot_api.logging.api_logger import ApiLogger 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_data.abc.server_repository_abc import ServerRepositoryABC 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): def __init__( self, + config: ConfigurationABC, logger: ApiLogger, bot: DiscordBotServiceABC, servers: ServerRepositoryABC, @@ -25,9 +29,11 @@ class TechnicianConfigMutation(QueryABC): db: DatabaseContextABC, config_service: ConfigService, tech_seeder: TechnicianConfigSeeder, + client_utils: ClientUtilsABC, ): QueryABC.__init__(self, "TechnicianConfigMutation") + self._config = config self._logger = logger self._bot = bot self._servers = servers @@ -35,6 +41,7 @@ class TechnicianConfigMutation(QueryABC): self._db = db self._config_service = config_service self._tech_seeder = tech_seeder + self._client_utils = client_utils self.set_field("updateTechnicianConfig", self.resolve_update_technician_config) @@ -62,7 +69,7 @@ class TechnicianConfigMutation(QueryABC): technician_config.max_steam_offer_count = ( input["maxSteamOfferCount"] if "maxSteamOfferCount" in input else technician_config.max_steam_offer_count ) - 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 @@ -97,6 +104,9 @@ class TechnicianConfigMutation(QueryABC): self._update_technician_ids(technician_config) 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()) return technician_config diff --git a/bot/src/bot_graphql/queries/technician_config_history_query.py b/bot/src/bot_graphql/queries/technician_config_history_query.py index 0db572bb..825acd7b 100644 --- a/bot/src/bot_graphql/queries/technician_config_history_query.py +++ b/bot/src/bot_graphql/queries/technician_config_history_query.py @@ -15,6 +15,7 @@ class TechnicianConfigHistoryQuery(HistoryQueryABC): self.set_field("waitForShutdown", lambda config, *_: config.wait_for_shutdown) self.set_field("cacheMaxMessages", lambda config, *_: config.cache_max_messages) self.set_field("maxSteamOfferCount", lambda config, *_: config.max_steam_offer_count) + self.set_field("maintenance", lambda config, *_: config.maintenance) self.add_collection( "featureFlag", lambda config, *_: List( diff --git a/bot/src/bot_graphql/queries/technician_config_query.py b/bot/src/bot_graphql/queries/technician_config_query.py index 1fdb2643..4809a60d 100644 --- a/bot/src/bot_graphql/queries/technician_config_query.py +++ b/bot/src/bot_graphql/queries/technician_config_query.py @@ -28,6 +28,7 @@ class TechnicianConfigQuery(DataQueryWithHistoryABC): self.set_field("waitForShutdown", lambda config, *_: config.wait_for_shutdown) self.set_field("cacheMaxMessages", lambda config, *_: config.cache_max_messages) self.set_field("maxSteamOfferCount", lambda config, *_: config.max_steam_offer_count) + self.set_field("maintenance", lambda config, *_: config.maintenance) self.add_collection( "featureFlag", lambda config, *_: List( diff --git a/bot/src/modules/database/database_extension.py b/bot/src/modules/database/database_extension.py index 1c26e70b..cdfe28fa 100644 --- a/bot/src/modules/database/database_extension.py +++ b/bot/src/modules/database/database_extension.py @@ -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_settings import FeatureFlagsSettings +from bot_core.environment_variables import MIGRATION_ONLY from bot_core.logging.database_logger import DatabaseLogger from bot_data.service.migration_service import MigrationService @@ -25,6 +26,6 @@ class DatabaseExtension(ApplicationExtensionABC): config.add_configuration("Database_StartTime", str(datetime.now())) migrations: MigrationService = services.get_service(MigrationService) migrations.migrate() - if config.get_configuration("MIGRATION_ONLY"): + if config.get_configuration(MIGRATION_ONLY): logger.warn(__name__, "Migrations finished. Stopping application...") sys.exit() diff --git a/web/src/app/models/config/technician-config.model.ts b/web/src/app/models/config/technician-config.model.ts index 36be69b6..1f211ee8 100644 --- a/web/src/app/models/config/technician-config.model.ts +++ b/web/src/app/models/config/technician-config.model.ts @@ -8,6 +8,7 @@ export interface TechnicianConfig extends DataWithHistory { waitForShutdown?: number; cacheMaxMessages?: number; maxSteamOfferCount?: number; + maintenance?: boolean; featureFlags: FeatureFlag[]; pingURLs: string[]; technicianIds: string[]; diff --git a/web/src/app/models/graphql/mutations.model.ts b/web/src/app/models/graphql/mutations.model.ts index 9bffdc58..4f52fa01 100644 --- a/web/src/app/models/graphql/mutations.model.ts +++ b/web/src/app/models/graphql/mutations.model.ts @@ -216,7 +216,7 @@ export class Mutations { `; 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 { updateTechnicianConfig(input: { id: $id, @@ -225,6 +225,7 @@ export class Mutations { waitForShutdown: $waitForShutdown, cacheMaxMessages: $cacheMaxMessages, maxSteamOfferCount: $maxSteamOfferCount, + maintenance: $maintenance, featureFlags: $featureFlags, pingURLs: $pingURLs, technicianIds: $technicianIds @@ -235,6 +236,7 @@ export class Mutations { waitForShutdown cacheMaxMessages maxSteamOfferCount + maintenance featureFlags { key value diff --git a/web/src/app/models/graphql/queries.model.ts b/web/src/app/models/graphql/queries.model.ts index 1f6bb6a9..9b8e8059 100644 --- a/web/src/app/models/graphql/queries.model.ts +++ b/web/src/app/models/graphql/queries.model.ts @@ -511,6 +511,7 @@ export class Queries { waitForShutdown cacheMaxMessages maxSteamOfferCount + maintenance featureFlags { key value diff --git a/web/src/app/modules/admin/settings/components/settings/settings.component.html b/web/src/app/modules/admin/settings/components/settings/settings.component.html index c3370289..2e9048ec 100644 --- a/web/src/app/modules/admin/settings/components/settings/settings.component.html +++ b/web/src/app/modules/admin/settings/components/settings/settings.component.html @@ -109,7 +109,8 @@
- +
@@ -136,7 +137,8 @@
{{'admin.settings.bot.help_url' | translate}}:
- +
@@ -145,7 +147,8 @@
{{'admin.settings.bot.wait_for_restart' | translate}}:
- +
@@ -154,7 +157,8 @@
{{'admin.settings.bot.wait_for_shutdown' | translate}}:
- +
@@ -163,7 +167,8 @@
{{'admin.settings.bot.cache_max_messages' | translate}}:
- +
@@ -172,14 +177,23 @@
{{'admin.settings.bot.max_steam_offer_count' | translate}}:
- +
+
+
+
{{'view.server.config.bot.maintenance' | translate}}:
+ +
+
+
- diff --git a/web/src/app/modules/admin/settings/components/settings/settings.component.ts b/web/src/app/modules/admin/settings/components/settings/settings.component.ts index 8b5462f0..428051d2 100644 --- a/web/src/app/modules/admin/settings/components/settings/settings.component.ts +++ b/web/src/app/modules/admin/settings/components/settings/settings.component.ts @@ -56,6 +56,10 @@ export class SettingsComponent implements OnInit { }; possibleTechnicians?: DiscordUser[]; + stateOptions: any[] = [ + { label: this.translate.instant("common.state.off"), value: false }, + { label: this.translate.instant("common.state.on"), value: true } + ]; constructor( private dataService: DataService, @@ -157,6 +161,7 @@ export class SettingsComponent implements OnInit { waitForShutdown: this.config.waitForShutdown, cacheMaxMessages: this.config.cacheMaxMessages, maxSteamOfferCount: this.config.maxSteamOfferCount, + maintenance: this.config.maintenance, featureFlags: this.config.featureFlags, pingURLs: this.config.pingURLs, technicianIds: this.config.technicianIds diff --git a/web/src/app/modules/shared/shared.module.ts b/web/src/app/modules/shared/shared.module.ts index d4ce44bf..b3ca8e60 100644 --- a/web/src/app/modules/shared/shared.module.ts +++ b/web/src/app/modules/shared/shared.module.ts @@ -35,6 +35,7 @@ import { InputSwitchModule } from "primeng/inputswitch"; import { CalendarModule } from "primeng/calendar"; import { DataImportAndExportComponent } from './components/data-import-and-export/data-import-and-export.component'; import { FileUploadModule } from "primeng/fileupload"; +import { SelectButtonModule } from "primeng/selectbutton"; const PrimeNGModules = [ @@ -64,6 +65,7 @@ const PrimeNGModules = [ InputSwitchModule, CalendarModule, FileUploadModule, + SelectButtonModule, ] @NgModule({ diff --git a/web/src/assets/i18n/de.json b/web/src/assets/i18n/de.json index 471a0893..e8a6e082 100644 --- a/web/src/assets/i18n/de.json +++ b/web/src/assets/i18n/de.json @@ -200,6 +200,10 @@ "role": "Rolle", "rule_count": "Regeln", "save": "Speichern", + "state": { + "off": "Aus", + "on": "Ein" + }, "user_warnings": "Verwarnungen", "users": "Benutzer", "value": "Wert", @@ -433,6 +437,7 @@ "header": "Bot Konfiguration", "help_voice_channel_id": "Sprachkanal für Hilfsbenachrichtung", "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_voice_state_hours": "Maximale Stunden für eine ontime nach Bot neustart", "message_delete_timer": "Zeit bis zum löschen einer Botnachricht in sekunden", diff --git a/web/src/assets/i18n/en.json b/web/src/assets/i18n/en.json index 539f3570..4f324ec6 100644 --- a/web/src/assets/i18n/en.json +++ b/web/src/assets/i18n/en.json @@ -200,6 +200,10 @@ "role": "Role", "rule_count": "Rules", "save": "Save", + "state": { + "off": "Off", + "on": "On" + }, "user_warnings": "User warnings", "users": "User", "value": "Value", @@ -433,6 +437,7 @@ "header": "Bot configuration", "help_voice_channel_id": "Voicechannel für help notifications", "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_voice_state_hours": "Max ontime hours after bot restart", "message_delete_timer": "Time to wait before delete bot messages", diff --git a/web/src/styles/themes/sh-edraft-dark-theme.scss b/web/src/styles/themes/sh-edraft-dark-theme.scss index 827d3933..6f483f02 100644 --- a/web/src/styles/themes/sh-edraft-dark-theme.scss +++ b/web/src/styles/themes/sh-edraft-dark-theme.scss @@ -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 { background-color: $primaryBackgroundColor !important; color: $primaryTextColor !important;