staging into master #426

Merged
edraft merged 83 commits from staging into master 2023-11-06 20:06:34 +01:00
32 changed files with 245 additions and 13 deletions
Showing only changes of commit 2caa910613 - Show all commits

@ -1 +1 @@
Subproject commit 954fd9bb341ff9ad66ffc9e293cbcde6ecb71326
Subproject commit 990c7df3ff9c84085795282e7cb2eaeb36603200

View File

@ -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

View File

@ -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,

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 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;
"""
)
)

View File

@ -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};
"""

View File

@ -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],
)

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.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

View File

@ -26,6 +26,7 @@ type Server implements TableWithHistoryQuery {
gameServers: [GameServer]
userCount: Int
activeUserCount: Int
users(filter: UserFilter, page: Page, sort: Sort): [User]
achievementCount: Int

View File

@ -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]

View File

@ -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(

View File

@ -76,6 +76,10 @@ class ServerQuery(DataQueryWithHistoryABC):
lambda server, *_: self._levels.get_levels_by_server_id(server.id),
LevelFilter,
)
self.set_field(
"activeUserCount",
lambda server, *_: self._users.get_users_by_server_id(server.id).where(lambda x: not x.left_server).count(),
)
self.add_collection(
"user",
lambda server, *_: self._users.get_users_by_server_id(server.id),

View File

@ -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(

View File

@ -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(

View File

@ -0,0 +1,31 @@
{
"DefaultLevel": {
"LevelHeader": "~~~ dev-Level ~~~",
"Levels": [
{
"Name": "dev-Newbie",
"Color": "0x1abc9c",
"MinXp": 0,
"Permissions": 968552209984
},
{
"Name": "dev-Keks",
"Color": "0x2ecc71",
"MinXp": 100,
"Permissions": 1002928856640
},
{
"Name": "dev-Doppelkeks",
"Color": "0x3498db",
"MinXp": 200,
"Permissions": 1071849660224
},
{
"Name": "dev-Auror",
"Color": "0xf1c40f",
"MinXp": 300,
"Permissions": 1089042120513
}
]
}
}

View File

@ -0,0 +1,31 @@
{
"DefaultLevel": {
"LevelHeader": "~~~ ed-Level ~~~",
"Levels": [
{
"Name": "ed-Newbie",
"Color": "0x1abc9c",
"MinXp": 0,
"Permissions": 968552209984
},
{
"Name": "ed-Keks",
"Color": "0x2ecc71",
"MinXp": 100,
"Permissions": 1002928856640
},
{
"Name": "ed-Doppelkeks",
"Color": "0x3498db",
"MinXp": 200,
"Permissions": 1071849660224
},
{
"Name": "ed-Auror",
"Color": "0xf1c40f",
"MinXp": 300,
"Permissions": 1089042120513
}
]
}
}

View File

@ -0,0 +1,31 @@
{
"DefaultLevel": {
"LevelHeader": "~~~ ed-Level ~~~",
"Levels": [
{
"Name": "ed-Newbie",
"Color": "0x1abc9c",
"MinXp": 0,
"Permissions": 968552209984
},
{
"Name": "ed-Keks",
"Color": "0x2ecc71",
"MinXp": 100,
"Permissions": 1002928856640
},
{
"Name": "ed-Doppelkeks",
"Color": "0x3498db",
"MinXp": 200,
"Permissions": 1071849660224
},
{
"Name": "ed-Auror",
"Color": "0xf1c40f",
"MinXp": 300,
"Permissions": 1089042120513
}
]
}
}

View File

@ -0,0 +1,31 @@
{
"DefaultLevel": {
"LevelHeader": "~~~ test-Level ~~~",
"Levels": [
{
"Name": "test-Newbie",
"Color": "0x1abc9c",
"MinXp": 0,
"Permissions": 968552209984
},
{
"Name": "test-Keks",
"Color": "0x2ecc71",
"MinXp": 100,
"Permissions": 1002928856640
},
{
"Name": "test-Doppelkeks",
"Color": "0x3498db",
"MinXp": 200,
"Permissions": 1071849660224
},
{
"Name": "test-Auror",
"Color": "0xf1c40f",
"MinXp": 300,
"Permissions": 1089042120513
}
]
}
}

View File

@ -32,7 +32,9 @@ class LevelModule(ModuleABC):
def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC):
cwd = env.working_directory
env.set_working_directory(os.path.dirname(os.path.realpath(__file__)))
config.add_json_file(f"default-level.json", optional=False)
config.add_json_file(f"config/default-level.json", optional=False)
config.add_json_file(f"config/default-level.{env.environment_name}.json", optional=True)
config.add_json_file(f"config/default-level.{env.host_name}.json", optional=True)
env.set_working_directory(cwd)
def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC):

View File

@ -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 = 250 # only look at first 500
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):

View File

@ -53,4 +53,4 @@
"tslib": "^2.4.1",
"typescript": "~4.9.5"
}
}
}

View File

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

View File

@ -23,6 +23,7 @@ export interface Server extends Data {
levelCount?: number;
levels?: Level[];
userCount?: number;
activeUserCount?: number;
users?: User[];
config?: ServerConfig;
hasFeatureFlag?: FeatureFlag;

View File

@ -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

View File

@ -68,6 +68,7 @@ export class Queries {
name
iconURL
userCount
activeUserCount
clients {
id
discordId
@ -497,6 +498,7 @@ export class Queries {
waitForRestart
waitForShutdown
cacheMaxMessages
maxSteamOfferCount
featureFlags {
key
value

View File

@ -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"

View File

@ -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

View File

@ -40,6 +40,7 @@
<i class="pi pi-users"></i>
{{server.userCount}}
{{'view.dashboard.server.member_count' | translate}}
{{'view.dashboard.server.active_members' | translate}} {{server ? server.activeUserCount : ''}}
</div>
</div>

View File

@ -23,9 +23,9 @@
</h3>
<div class="data">
<i class="pi pi-users"></i>
{{server ? server.userCount : ''}}
<i class="pi pi-users"></i> {{server ? server.userCount : ''}}
{{'view.dashboard.server.member_count' | translate}}
{{'view.dashboard.server.active_members' | translate}} {{server ? server.activeUserCount : ''}}
</div>
<div class="client-data"

View File

@ -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",
@ -359,6 +360,7 @@
},
"header": "Dashboard",
"server": {
"active_members": "davon aktiv:",
"header": "Server",
"member_count": "Mitglied(er)"
},

View File

@ -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",
@ -359,6 +360,7 @@
},
"header": "Dashboard",
"server": {
"active_members": "active:",
"header": "Server",
"member_count": "Member(s)"
},

View File

@ -45,7 +45,6 @@ header,
.p-panelmenu-header > a {
border: none !important;
border-radius: unset !important;
font-weight: unset !important;
transition: none !important;
}