Fixed level seeder #28

This commit is contained in:
Sven Heidemann 2022-11-08 17:49:42 +01:00
parent fe32604a14
commit faaadb0009

View File

@ -29,14 +29,14 @@ class LevelSeeder(DataSeederABC):
async def _create_level(self, level: Level, guild: Guild, server: Server): async def _create_level(self, level: Level, guild: Guild, server: Server):
level.server = server level.server = server
try: try:
if guild.roles.where(lambda r: r.name == level.name).first_or_default() is not None: if guild.roles.where(lambda r: r.name == level.name).first_or_default() is None:
return
await guild.create_role(name=level.name, colour=Colour(int(level.color, 16)), hoist=False, mentionable=True, permissions=Permissions(level.permissions)) 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}') self._logger.debug(__name__, f'Created role {level.name}')
if self._levels.find_levels_by_server_id(server.server_id).where(lambda l: l == level).first_or_default() is not None: levels = self._levels.find_levels_by_server_id(server.server_id)
if levels is None or levels.where(lambda l: l == level).first_or_default() is None:
self._levels.add_level(level) self._levels.add_level(level)
self._logger.debug(__name__, f'Saved level {level.name}')
except discord.errors.Forbidden as e: except discord.errors.Forbidden as e:
self._logger.error(__name__, f'Creating level failed', e) self._logger.error(__name__, f'Creating level failed', e)
level.permissions = 0 level.permissions = 0