staging into master #426
 Submodule bot/src/bot/config updated: 954fd9bb34...990c7df3ff
									
								
							| @@ -9,7 +9,7 @@ from bot.application import Application | ||||
| from bot.extension.init_bot_extension import InitBotExtension | ||||
| from bot.startup import Startup | ||||
| from bot.startup_discord_extension import StartupDiscordExtension | ||||
| from bot.startup_migration_extension import StartupMigrationExtension | ||||
| from bot_data.startup_migration_extension import StartupMigrationExtension | ||||
| from bot.startup_module_extension import StartupModuleExtension | ||||
| from bot.startup_settings_extension import StartupSettingsExtension | ||||
| from bot_api.app_api_extension import AppApiExtension | ||||
|   | ||||
| @@ -5,6 +5,7 @@ CREATE TABLE IF NOT EXISTS `CFG_TechnicianHistory` | ||||
|     `WaitForRestart`          BIGINT       NOT NULL DEFAULT 8, | ||||
|     `WaitForShutdown`         BIGINT       NOT NULL DEFAULT 8, | ||||
|     `CacheMaxMessages`        BIGINT       NOT NULL DEFAULT 1000000, | ||||
|     `MaxSteamOfferCount`      BIGINT       NOT NULL DEFAULT 250, | ||||
|     `FeatureFlags`            JSON         NULL     DEFAULT ('{}'), | ||||
|     `Deleted`                 BOOL                  DEFAULT FALSE, | ||||
|     `DateFrom`                DATETIME(6)  NOT NULL, | ||||
| @@ -23,6 +24,7 @@ BEGIN | ||||
|                                          `WaitForRestart`, | ||||
|                                          `WaitForShutdown`, | ||||
|                                          `CacheMaxMessages`, | ||||
|                                          `MaxSteamOfferCount`, | ||||
|                                          `FeatureFlags`, | ||||
|                                          `DateFrom`, | ||||
|                                          `DateTo`) | ||||
| @@ -31,6 +33,7 @@ BEGIN | ||||
|             OLD.WaitForRestart, | ||||
|             OLD.WaitForShutdown, | ||||
|             OLD.CacheMaxMessages, | ||||
|             OLD.MaxSteamOfferCount, | ||||
|             OLD.FeatureFlags, | ||||
|             OLD.LastModifiedAt, | ||||
|             CURRENT_TIMESTAMP(6)); | ||||
| @@ -48,6 +51,7 @@ BEGIN | ||||
|                                          `WaitForRestart`, | ||||
|                                          `WaitForShutdown`, | ||||
|                                          `CacheMaxMessages`, | ||||
|                                          `MaxSteamOfferCount`, | ||||
|                                          `FeatureFlags`, | ||||
|                                          `Deleted`, | ||||
|                                          `DateFrom`, | ||||
| @@ -57,6 +61,7 @@ BEGIN | ||||
|             OLD.WaitForRestart, | ||||
|             OLD.WaitForShutdown, | ||||
|             OLD.CacheMaxMessages, | ||||
|             OLD.MaxSteamOfferCount, | ||||
|             OLD.FeatureFlags, | ||||
|             TRUE, | ||||
|             OLD.LastModifiedAt, | ||||
|   | ||||
| @@ -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 MaxSteamOfferCountMigration(MigrationABC): | ||||
|     name = "1.2.0_MaxSteamOfferCountMigration" | ||||
|  | ||||
|     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 MaxSteamOfferCount BIGINT NOT NULL DEFAULT 250 AFTER CacheMaxMessages; | ||||
|                 """ | ||||
|             ) | ||||
|         ) | ||||
|  | ||||
|         self._cursor.execute( | ||||
|             str( | ||||
|                 f""" | ||||
|                     ALTER TABLE CFG_TechnicianHistory | ||||
|                     ADD MaxSteamOfferCount BIGINT NOT NULL DEFAULT 250 AFTER CacheMaxMessages; | ||||
|                 """ | ||||
|             ) | ||||
|         ) | ||||
|         self._exec(__file__, "config/technician.sql") | ||||
|  | ||||
|     def downgrade(self): | ||||
|         self._cursor.execute( | ||||
|             str( | ||||
|                 f""" | ||||
|                     ALTER TABLE CFG_Technician DROP COLUMN MaxSteamOfferCount; | ||||
|                 """ | ||||
|             ) | ||||
|         ) | ||||
|         self._cursor.execute( | ||||
|             str( | ||||
|                 f""" | ||||
|                     ALTER TABLE CFG_TechnicianHistory DROP COLUMN MaxSteamOfferCount; | ||||
|                 """ | ||||
|             ) | ||||
|         ) | ||||
| @@ -15,6 +15,7 @@ class TechnicianConfig(TableABC, ConfigurationModelABC): | ||||
|         wait_for_restart: int, | ||||
|         wait_for_shutdown: int, | ||||
|         cache_max_messages: int, | ||||
|         max_steam_offer_count: int, | ||||
|         feature_flags: dict[FeatureFlagsEnum], | ||||
|         technician_ids: List[int], | ||||
|         ping_urls: List[str], | ||||
| @@ -27,6 +28,7 @@ class TechnicianConfig(TableABC, ConfigurationModelABC): | ||||
|         self._wait_for_restart = wait_for_restart | ||||
|         self._wait_for_shutdown = wait_for_shutdown | ||||
|         self._cache_max_messages = cache_max_messages | ||||
|         self._max_steam_offer_count = max_steam_offer_count | ||||
|         self._feature_flags = feature_flags | ||||
|         self._technician_ids = technician_ids | ||||
|         self._ping_urls = ping_urls | ||||
| @@ -71,6 +73,14 @@ class TechnicianConfig(TableABC, ConfigurationModelABC): | ||||
|     def cache_max_messages(self, value: int): | ||||
|         self._cache_max_messages = value | ||||
|  | ||||
|     @property | ||||
|     def max_steam_offer_count(self) -> int: | ||||
|         return self._max_steam_offer_count | ||||
|  | ||||
|     @max_steam_offer_count.setter | ||||
|     def max_steam_offer_count(self, value: int): | ||||
|         self._max_steam_offer_count = value | ||||
|  | ||||
|     @property | ||||
|     def feature_flags(self) -> dict[FeatureFlagsEnum]: | ||||
|         return self._feature_flags | ||||
| @@ -117,12 +127,13 @@ class TechnicianConfig(TableABC, ConfigurationModelABC): | ||||
|         return str( | ||||
|             f""" | ||||
|                 INSERT INTO `CFG_Technician` ( | ||||
|                     `HelpCommandReferenceUrl`, `WaitForRestart`, `WaitForShutdown`, `CacheMaxMessages`, `FeatureFlags` | ||||
|                     `HelpCommandReferenceUrl`, `WaitForRestart`, `WaitForShutdown`, `CacheMaxMessages`, `MaxSteamOfferCount`, `FeatureFlags` | ||||
|                 ) VALUES ( | ||||
|                     '{self._help_command_reference_url}', | ||||
|                     {self._wait_for_restart}, | ||||
|                     {self._wait_for_shutdown}, | ||||
|                     {self._cache_max_messages}, | ||||
|                     {self._max_steam_offer_count}, | ||||
|                     '{json.dumps(self._feature_flags)}' | ||||
|                 ); | ||||
|             """ | ||||
| @@ -137,6 +148,7 @@ class TechnicianConfig(TableABC, ConfigurationModelABC): | ||||
|                 `WaitForRestart` = {self._wait_for_restart}, | ||||
|                 `WaitForShutdown` = {self._wait_for_shutdown}, | ||||
|                 `CacheMaxMessages` = {self._cache_max_messages}, | ||||
|                 `MaxSteamOfferCount` = {self._max_steam_offer_count}, | ||||
|                 `FeatureFlags` = '{json.dumps(self._feature_flags)}' | ||||
|                 WHERE `Id` = {self._id}; | ||||
|             """ | ||||
|   | ||||
| @@ -46,11 +46,12 @@ class TechnicianConfigRepositoryService(TechnicianConfigRepositoryABC): | ||||
|             result[2], | ||||
|             result[3], | ||||
|             result[4], | ||||
|             json.loads(result[5]), | ||||
|             result[5], | ||||
|             json.loads(result[6]), | ||||
|             self._get_technician_ids(), | ||||
|             self._get_technician_ping_urls(), | ||||
|             result[6], | ||||
|             result[7], | ||||
|             result[8], | ||||
|             id=result[0], | ||||
|         ) | ||||
|  | ||||
|   | ||||
| @@ -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.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 | ||||
| from bot_data.migration.short_role_name_only_highest_migration import ( | ||||
| @@ -68,3 +69,4 @@ class StartupMigrationExtension(StartupExtensionABC): | ||||
|         services.add_transient(MigrationABC, FixUserHistoryMigration)  # 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, MaxSteamOfferCountMigration)  # 04.11.2023 #188 - 1.2.0 | ||||
| @@ -4,6 +4,7 @@ type TechnicianConfig implements TableWithHistoryQuery { | ||||
|     waitForRestart: Int | ||||
|     waitForShutdown: Int | ||||
|     cacheMaxMessages: Int | ||||
|     maxSteamOfferCount: Int | ||||
|     featureFlagCount: Int | ||||
|     featureFlags: [FeatureFlag] | ||||
|     pingURLs: [String] | ||||
| @@ -23,6 +24,7 @@ type TechnicianConfigHistory implements HistoryTableQuery { | ||||
|     waitForRestart: Int | ||||
|     waitForShutdown: Int | ||||
|     cacheMaxMessages: Int | ||||
|     maxSteamOfferCount: Int | ||||
|     featureFlagCount: Int | ||||
|     featureFlags: [FeatureFlag] | ||||
|  | ||||
| @@ -59,6 +61,7 @@ input TechnicianConfigInput { | ||||
|     waitForRestart: Int | ||||
|     waitForShutdown: Int | ||||
|     cacheMaxMessages: Int | ||||
|     maxSteamOfferCount: Int | ||||
|     featureFlags: [FeatureFlagInput] | ||||
|     pingURLs: [String] | ||||
|     technicianIds: [String] | ||||
|   | ||||
| @@ -59,6 +59,9 @@ class TechnicianConfigMutation(QueryABC): | ||||
|         technician_config.cache_max_messages = ( | ||||
|             input["cacheMaxMessages"] if "cacheMaxMessages" in input else technician_config.cache_max_messages | ||||
|         ) | ||||
|         technician_config.max_steam_offer_count = ( | ||||
|             input["maxSteamOfferCount"] if "maxSteamOfferCount" in input else technician_config.max_steam_offer_count | ||||
|         ) | ||||
|         old_feature_flags = technician_config.feature_flags | ||||
|         technician_config.feature_flags = ( | ||||
|             dict( | ||||
|   | ||||
| @@ -14,6 +14,7 @@ class TechnicianConfigHistoryQuery(HistoryQueryABC): | ||||
|         self.set_field("waitForRestart", lambda config, *_: config.wait_for_restart) | ||||
|         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.add_collection( | ||||
|             "featureFlag", | ||||
|             lambda config, *_: List( | ||||
|   | ||||
| @@ -27,6 +27,7 @@ class TechnicianConfigQuery(DataQueryWithHistoryABC): | ||||
|         self.set_field("waitForRestart", lambda config, *_: config.wait_for_restart) | ||||
|         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.add_collection( | ||||
|             "featureFlag", | ||||
|             lambda config, *_: List( | ||||
|   | ||||
| @@ -21,6 +21,7 @@ from bot_data.abc.steam_special_offer_repository_abc import ( | ||||
| ) | ||||
| from bot_data.model.server_config import ServerConfig | ||||
| from bot_data.model.steam_special_offer import SteamSpecialOffer | ||||
| from bot_data.model.technician_config import TechnicianConfig | ||||
|  | ||||
|  | ||||
| class SteamOfferWatcher(TaskABC): | ||||
| @@ -33,6 +34,7 @@ class SteamOfferWatcher(TaskABC): | ||||
|         offers: SteamSpecialOfferRepositoryABC, | ||||
|         message_service: MessageService, | ||||
|         t: TranslatePipe, | ||||
|         tech_config: TechnicianConfig, | ||||
|     ): | ||||
|         TaskABC.__init__(self) | ||||
|  | ||||
| @@ -43,6 +45,7 @@ class SteamOfferWatcher(TaskABC): | ||||
|         self._bot = bot | ||||
|         self._message_service = message_service | ||||
|         self._t = t | ||||
|         self._tech_config = tech_config | ||||
|  | ||||
|         self._is_new = False | ||||
|         self._urls = {} | ||||
| @@ -108,8 +111,7 @@ class SteamOfferWatcher(TaskABC): | ||||
|     def _get_new_game_offers(self) -> List[SteamSpecialOffer]: | ||||
|         new_offers = List(SteamSpecialOffer) | ||||
|  | ||||
|         # sale_count = self._get_max_count() + 100 | ||||
|         sale_count = 150 | ||||
|         sale_count = self._tech_config.max_steam_offer_count | ||||
|         # todo: let admins change the value | ||||
|         self._logger.debug(__name__, f"Get special offers from 0 to {sale_count}") | ||||
|         for i in range(0, sale_count, 100): | ||||
|   | ||||
| @@ -53,4 +53,4 @@ | ||||
|         "tslib": "^2.4.1", | ||||
|         "typescript": "~4.9.5" | ||||
|     } | ||||
| } | ||||
| } | ||||
| @@ -7,6 +7,7 @@ export interface TechnicianConfig extends DataWithHistory { | ||||
|   waitForRestart?: number; | ||||
|   waitForShutdown?: number; | ||||
|   cacheMaxMessages?: number; | ||||
|   maxSteamOfferCount?: number; | ||||
|   featureFlags: FeatureFlag[]; | ||||
|   pingURLs: string[]; | ||||
|   technicianIds: string[]; | ||||
|   | ||||
| @@ -216,7 +216,7 @@ export class Mutations { | ||||
|   `; | ||||
|  | ||||
|   static updateTechnicianConfig = ` | ||||
|     mutation updateTechnicianConfig($id: ID, $helpCommandReferenceUrl: String, $waitForRestart: Int, $waitForShutdown: Int, $cacheMaxMessages: Int, $featureFlags: [FeatureFlagInput], $pingURLs: [String], $technicianIds: [String]) { | ||||
|     mutation updateTechnicianConfig($id: ID, $helpCommandReferenceUrl: String, $waitForRestart: Int, $waitForShutdown: Int, $cacheMaxMessages: Int, $maxSteamOfferCount: Int, $featureFlags: [FeatureFlagInput], $pingURLs: [String], $technicianIds: [String]) { | ||||
|       technicianConfig { | ||||
|         updateTechnicianConfig(input: { | ||||
|             id: $id, | ||||
| @@ -224,6 +224,7 @@ export class Mutations { | ||||
|             waitForRestart: $waitForRestart, | ||||
|             waitForShutdown: $waitForShutdown, | ||||
|             cacheMaxMessages: $cacheMaxMessages, | ||||
|             maxSteamOfferCount: $maxSteamOfferCount, | ||||
|             featureFlags: $featureFlags, | ||||
|             pingURLs: $pingURLs, | ||||
|             technicianIds: $technicianIds | ||||
| @@ -233,6 +234,7 @@ export class Mutations { | ||||
|           waitForRestart | ||||
|           waitForShutdown | ||||
|           cacheMaxMessages | ||||
|           maxSteamOfferCount | ||||
|           featureFlags { | ||||
|             key | ||||
|             value | ||||
|   | ||||
| @@ -497,6 +497,7 @@ export class Queries { | ||||
|         waitForRestart | ||||
|         waitForShutdown | ||||
|         cacheMaxMessages | ||||
|         maxSteamOfferCount | ||||
|         featureFlags { | ||||
|           key | ||||
|           value | ||||
|   | ||||
| @@ -168,6 +168,15 @@ | ||||
|       </div> | ||||
|     </div> | ||||
|  | ||||
|     <div class="content-row"> | ||||
|       <div class="content-column"> | ||||
|         <div class="content-data-name">{{'admin.settings.bot.max_steam_offer_count' | translate}}:</div> | ||||
|         <div class="content-data-value"> | ||||
|           <input type="number" pInputText [(ngModel)]="config.maxSteamOfferCount" placeholder="{{'admin.settings.bot.max_steam_offer_count' | translate}}"> | ||||
|         </div> | ||||
|       </div> | ||||
|     </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.technician_ids" [options]="possibleTechnicians" optionLabel="name" optionValue="id" | ||||
|   | ||||
| @@ -156,6 +156,7 @@ export class SettingsComponent implements OnInit { | ||||
|         waitForRestart: this.config.waitForRestart, | ||||
|         waitForShutdown: this.config.waitForShutdown, | ||||
|         cacheMaxMessages: this.config.cacheMaxMessages, | ||||
|         maxSteamOfferCount: this.config.maxSteamOfferCount, | ||||
|         featureFlags: this.config.featureFlags, | ||||
|         pingURLs: this.config.pingURLs, | ||||
|         technicianIds: this.config.technicianIds | ||||
|   | ||||
| @@ -27,6 +27,7 @@ | ||||
|         "cache_max_messages": "Anzahl der Nachrichten im cache", | ||||
|         "header": "Bot", | ||||
|         "help_url": "Befehlsreferenz", | ||||
|         "max_steam_offer_count": "Maximal zu betrachtende Steam Angebote", | ||||
|         "ping_urls": "Ping Adressen", | ||||
|         "technician_ids": "Techniker Ids", | ||||
|         "wait_for_restart": "Wartezeit vor Neustart", | ||||
|   | ||||
| @@ -27,6 +27,7 @@ | ||||
|         "cache_max_messages": "Number of messages in cache", | ||||
|         "header": "Bot", | ||||
|         "help_url": "Help URL", | ||||
|         "max_steam_offer_count": "Maximum monitoring steam offers", | ||||
|         "ping_urls": "Ping addresses", | ||||
|         "technician_ids": "Technician Ids", | ||||
|         "wait_for_restart": "Time to wait before restart", | ||||
|   | ||||
		Reference in New Issue
	
	Block a user