Fixed level service #166

This commit is contained in:
Sven Heidemann 2023-01-11 17:10:02 +01:00
parent 706b6732eb
commit b89fa12ec6

View File

@ -42,8 +42,15 @@ class LevelService:
self._t = t self._t = t
def get_level(self, user: User) -> Level: 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) levels_by_server = self._levels.get_levels_by_server_id(user.server.server_id)
return levels.where(lambda l: user.xp >= l.min_xp).last() 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): 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) level_names = self._levels.get_levels_by_server_id(user.server.server_id).select(lambda l: l.name)