Reload levelsystem after mutate levels #245

This commit is contained in:
Sven Heidemann 2023-03-06 08:30:43 +01:00
parent a701807831
commit 22d26bf032

View File

@ -1,24 +1,30 @@
from cpl_core.database.context import DatabaseContextABC from cpl_core.database.context import DatabaseContextABC
from cpl_discord.service import DiscordBotServiceABC
from bot_data.abc.level_repository_abc import LevelRepositoryABC from bot_data.abc.level_repository_abc import LevelRepositoryABC
from bot_data.abc.server_repository_abc import ServerRepositoryABC from bot_data.abc.server_repository_abc import ServerRepositoryABC
from bot_data.model.level import Level from bot_data.model.level import Level
from bot_data.model.user_role_enum import UserRoleEnum from bot_data.model.user_role_enum import UserRoleEnum
from bot_graphql.abc.query_abc import QueryABC from bot_graphql.abc.query_abc import QueryABC
from modules.level.level_seeder import LevelSeeder
class LevelMutation(QueryABC): class LevelMutation(QueryABC):
def __init__( def __init__(
self, self,
bot: DiscordBotServiceABC,
servers: ServerRepositoryABC, servers: ServerRepositoryABC,
levels: LevelRepositoryABC, levels: LevelRepositoryABC,
db: DatabaseContextABC, db: DatabaseContextABC,
level_seeder: LevelSeeder,
): ):
QueryABC.__init__(self, "LevelMutation") QueryABC.__init__(self, "LevelMutation")
self._bot = bot
self._servers = servers self._servers = servers
self._levels = levels self._levels = levels
self._db = db self._db = db
self._level_seeder = level_seeder
self.set_field("createLevel", self.resolve_create_level) self.set_field("createLevel", self.resolve_create_level)
self.set_field("updateLevel", self.resolve_update_level) self.set_field("updateLevel", self.resolve_update_level)
@ -46,6 +52,7 @@ class LevelMutation(QueryABC):
and l.permissions == level.permissions and l.permissions == level.permissions
) )
self._bot.loop.create_task(self._level_seeder.seed())
return self._levels.get_levels_by_server_id(level.server.id).where(get_new_level).last() return self._levels.get_levels_by_server_id(level.server.id).where(get_new_level).last()
def resolve_update_level(self, *_, input: dict): def resolve_update_level(self, *_, input: dict):
@ -60,6 +67,7 @@ class LevelMutation(QueryABC):
self._levels.update_level(level) self._levels.update_level(level)
self._db.save_changes() self._db.save_changes()
self._bot.loop.create_task(self._level_seeder.seed())
level = self._levels.get_level_by_id(input["id"]) level = self._levels.get_level_by_id(input["id"])
return level return level
@ -69,4 +77,6 @@ class LevelMutation(QueryABC):
self._levels.delete_level(level) self._levels.delete_level(level)
self._db.save_changes() self._db.save_changes()
self._bot.loop.create_task(self._level_seeder.seed())
return level return level