Update level permission by db state on level seeding
All checks were successful
Deploy prod on push / pre-build (push) Successful in 2s
Deploy prod on push / build-bot (push) Successful in 3m15s
Deploy prod on push / build-web (push) Successful in 1m54s
Deploy prod on push / deploy (push) Successful in 24s

This commit is contained in:
Sven Heidemann 2024-02-12 14:19:31 +01:00
parent bb0ff1c560
commit 414720f53b

View File

@ -104,7 +104,8 @@ class LevelSeeder(DataSeederABC):
levels = levels.order_by_descending(lambda l: l.min_xp) 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 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): for role in guild.roles.order_by_descending(lambda r: r.position):
if levels.where(lambda l: l.name == role.name).count() == 0: level = levels.where(lambda l: l.name == role.name).first_or_default()
if level is None:
continue continue
new_position = position_above_levels - ( new_position = position_above_levels - (
@ -117,7 +118,7 @@ class LevelSeeder(DataSeederABC):
__name__, __name__,
f"Moved {role.name} from {role.position} to {new_position}", f"Moved {role.name} from {role.position} to {new_position}",
) )
await role.edit(position=new_position) await role.edit(permissions=level.permissions, position=new_position)
except Exception as e: except Exception as e:
self._logger.error(__name__, f"Cannot change position of {role.name}", e) self._logger.error(__name__, f"Cannot change position of {role.name}", e)