0.3 #146

Merged
edraft merged 359 commits from 0.3 into master 2023-01-12 07:04:40 +01:00
Showing only changes of commit 6e39154c75 - Show all commits

View File

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