From 6a18b15447682122351db4974e72e70689c42871 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Mon, 7 Nov 2022 20:35:24 +0100 Subject: [PATCH] Fixed level stuff #90 --- kdb-bot/src/modules/level/level_seeder.py | 12 ++++++++++-- kdb-bot/src/modules/level/service/level_service.py | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/kdb-bot/src/modules/level/level_seeder.py b/kdb-bot/src/modules/level/level_seeder.py index 9a1148bb49..870a7b3024 100644 --- a/kdb-bot/src/modules/level/level_seeder.py +++ b/kdb-bot/src/modules/level/level_seeder.py @@ -1,3 +1,4 @@ +import discord from cpl_discord.container import Guild, Role from cpl_discord.service import DiscordBotServiceABC from cpl_query.extension import List @@ -26,14 +27,20 @@ class LevelSeeder(DataSeederABC): self._default_levels = levels.levels.order_by_descending(lambda l: l.min_xp) async def _create_level(self, level: Level, guild: Guild, server: Server): + level.server = server try: if guild.roles.where(lambda r: r.name == level.name).first_or_default() is not None: return await guild.create_role(name=level.name, colour=Colour(int(level.color, 16)), hoist=False, mentionable=True, permissions=Permissions(level.permissions)) self._logger.info(__name__, f'Created level {level.name}') - level.server = server - self._levels.add_level(level) + + if self._levels.find_levels_by_server_id(server.server_id).where(lambda l: l == level).first_or_default() is not None: + self._levels.add_level(level) + except discord.errors.Forbidden as e: + self._logger.error(__name__, f'Creating level failed', e) + level.permissions = 0 + self._levels.update_level(level) except Exception as e: self._logger.error(__name__, f'Creating level failed', e) @@ -66,6 +73,7 @@ class LevelSeeder(DataSeederABC): if created_default: continue + levels = levels.order_by_descending(lambda l: l.min_xp) position_above_levels = guild.roles.where(lambda r: r.name == self._level_header).single().position for role in guild.roles.order_by_descending(lambda r: r.position): if levels.where(lambda l: l.name == role.name).count() == 0: diff --git a/kdb-bot/src/modules/level/service/level_service.py b/kdb-bot/src/modules/level/service/level_service.py index bf53b11ce8..f47102b9dc 100644 --- a/kdb-bot/src/modules/level/service/level_service.py +++ b/kdb-bot/src/modules/level/service/level_service.py @@ -76,7 +76,7 @@ class LevelService: level_settings: LevelServerSettings = self._config.get_configuration(f'LevelServerSettings_{guild.id}') await self._message_service.send_channel_message( self._bot.get_channel(level_settings.changed_level_notification_channel), - self._t.transform('modules.level.new_level_message'.format(member.id, level.name)), + self._t.transform('modules.level.new_level_message').format(member.id, level.name), is_persistent=True )