From b89fa12ec66773b0fa7bb36e82f50055ee3138d0 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Wed, 11 Jan 2023 17:10:02 +0100 Subject: [PATCH] Fixed level service #166 --- kdb-bot/src/modules/level/service/level_service.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/kdb-bot/src/modules/level/service/level_service.py b/kdb-bot/src/modules/level/service/level_service.py index e49d6f31..7bd7f2d6 100644 --- a/kdb-bot/src/modules/level/service/level_service.py +++ b/kdb-bot/src/modules/level/service/level_service.py @@ -42,8 +42,15 @@ class LevelService: self._t = t def get_level(self, user: User) -> Level: - levels = self._levels.get_levels_by_server_id(user.server.server_id).order_by(lambda l: l.min_xp) - return levels.where(lambda l: user.xp >= l.min_xp).last() + levels_by_server = self._levels.get_levels_by_server_id(user.server.server_id) + levels = levels_by_server \ + .order_by(lambda l: l.min_xp) \ + .where(lambda l: user.xp >= l.min_xp) + + if levels.count() == 0: + return levels_by_server.order_by(lambda l: l.min_xp).last() + + return levels.last() async def set_level(self, user: User): level_names = self._levels.get_levels_by_server_id(user.server.server_id).select(lambda l: l.name)