diff --git a/kdb-bot/src/modules/achievements/achievement_attribute_resolver.py b/kdb-bot/src/modules/achievements/achievement_attribute_resolver.py index 4badad37..f08f1579 100644 --- a/kdb-bot/src/modules/achievements/achievement_attribute_resolver.py +++ b/kdb-bot/src/modules/achievements/achievement_attribute_resolver.py @@ -44,3 +44,7 @@ class AchievementAttributeResolver: def get_played_on_game_server(self, user: User) -> List[str]: joins = self._user_joined_game_server.get_user_joined_game_servers_by_user_id(user.id) return joins.select(lambda x: x.game_server.name) + + def get_last_ontime_hours(self, user: User) -> int: + ujvs = self._user_joined_voice_channels.get_user_joined_voice_channels_by_user_id(user.id) + return int(str(ujvs.max(lambda join: (join.leaved_on - join.joined_on).total_seconds() / 3600))) diff --git a/kdb-bot/src/modules/achievements/achievement_service.py b/kdb-bot/src/modules/achievements/achievement_service.py index 17486f80..b446d095 100644 --- a/kdb-bot/src/modules/achievements/achievement_service.py +++ b/kdb-bot/src/modules/achievements/achievement_service.py @@ -48,7 +48,9 @@ class AchievementService: AchievementAttribute( "played_on_game_server", lambda user: resolver.get_played_on_game_server(user), "GameServer" ), - AchievementAttribute("last_single_ontime_hours", lambda user: user.level, "GameServer"), + AchievementAttribute( + "last_single_ontime_hours", lambda user: resolver.get_last_ontime_hours(user), "number" + ), ] ) @@ -62,6 +64,9 @@ class AchievementService: "contains": lambda value, expected_value: expected_value in value, } + def add_achievement_attribute(self, atr: AchievementAttribute): + self._attributes.add(atr) + def get_operators(self) -> list[str]: return [x for x in self._operators.keys()]