From 22d26bf032f796c10ccdc9f25f94a3caa57a3377 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Mon, 6 Mar 2023 08:30:43 +0100 Subject: [PATCH] Reload levelsystem after mutate levels #245 --- kdb-bot/src/bot_graphql/mutations/level_mutation.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/kdb-bot/src/bot_graphql/mutations/level_mutation.py b/kdb-bot/src/bot_graphql/mutations/level_mutation.py index b981384a..47f61e7c 100644 --- a/kdb-bot/src/bot_graphql/mutations/level_mutation.py +++ b/kdb-bot/src/bot_graphql/mutations/level_mutation.py @@ -1,24 +1,30 @@ 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.server_repository_abc import ServerRepositoryABC from bot_data.model.level import Level from bot_data.model.user_role_enum import UserRoleEnum from bot_graphql.abc.query_abc import QueryABC +from modules.level.level_seeder import LevelSeeder class LevelMutation(QueryABC): def __init__( self, + bot: DiscordBotServiceABC, servers: ServerRepositoryABC, levels: LevelRepositoryABC, db: DatabaseContextABC, + level_seeder: LevelSeeder, ): QueryABC.__init__(self, "LevelMutation") + self._bot = bot self._servers = servers self._levels = levels self._db = db + self._level_seeder = level_seeder self.set_field("createLevel", self.resolve_create_level) self.set_field("updateLevel", self.resolve_update_level) @@ -46,6 +52,7 @@ class LevelMutation(QueryABC): 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() def resolve_update_level(self, *_, input: dict): @@ -60,6 +67,7 @@ class LevelMutation(QueryABC): self._levels.update_level(level) self._db.save_changes() + self._bot.loop.create_task(self._level_seeder.seed()) level = self._levels.get_level_by_id(input["id"]) return level @@ -69,4 +77,6 @@ class LevelMutation(QueryABC): self._levels.delete_level(level) self._db.save_changes() + + self._bot.loop.create_task(self._level_seeder.seed()) return level