From 6e39154c75a908e285dcd306d03308c57f3e52e4 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Sun, 6 Nov 2022 21:54:21 +0100 Subject: [PATCH] Fixed level assignment #25 --- kdb-bot/src/modules/level/service/level_service.py | 6 ++++-- 1 file changed, 4 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 95fbcae623..292d548aad 100644 --- a/kdb-bot/src/modules/level/service/level_service.py +++ b/kdb-bot/src/modules/level/service/level_service.py @@ -1,3 +1,5 @@ +import asyncio + import discord from cpl_core.database.context import DatabaseContextABC from cpl_core.logging import LoggerABC @@ -31,12 +33,11 @@ class LevelService: 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).first() + return levels.where(lambda l: user.xp >= l.min_xp).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) guild: Guild = self._bot.guilds.where(lambda g: g.id == user.server.discord_server_id).single() - level_role: Role = guild.roles.where(lambda r: r.name == self.get_level(user).name).single() member: Member = guild.members.where(lambda m: m.id == user.discord_id).single() for role in member.roles: if role.name not in level_names.to_list(): @@ -49,6 +50,7 @@ class LevelService: except Exception as e: self._logger.error(__name__, f'Removing role {role.name} from {member.name} failed!', e) + level_role: Role = guild.roles.where(lambda r: r.name == self.get_level(user).name).single() if level_role in member.roles: return try: