Merge pull request 'Der Bot muss wohl zwei mal gestartet werden, damit er die DB richtig läd #214' (#231) from #214 into 1.0.0

Reviewed-on: sh-edraft.de/kd_discord_bot#231
Reviewed-by: Ebola-Chan <nick.jungmann@gmail.com>
Closes #214
This commit is contained in:
Sven Heidemann 2023-02-21 20:43:05 +01:00
commit 0f26db3d74
3 changed files with 7 additions and 3 deletions

View File

@ -25,10 +25,10 @@ class ModuleList:
DataModule, DataModule,
GraphQLModule, GraphQLModule,
PermissionModule, PermissionModule,
LevelModule,
DatabaseModule, DatabaseModule,
AutoRoleModule, AutoRoleModule,
BaseModule, BaseModule,
LevelModule,
ApiModule, ApiModule,
TechnicianModule, TechnicianModule,
# has to be last! # has to be last!

View File

@ -375,8 +375,6 @@ class DatabaseOnReadyEvent(OnReadyABC):
async def on_ready(self): async def on_ready(self):
self._logger.debug(__name__, f"Module {type(self)} started") self._logger.debug(__name__, f"Module {type(self)} started")
await self._seeder.seed()
self._check_known_users() self._check_known_users()
self._check_servers() self._check_servers()
self._check_clients() self._check_clients()
@ -385,5 +383,7 @@ class DatabaseOnReadyEvent(OnReadyABC):
self._check_user_joins_vc() self._check_user_joins_vc()
self._check_user_joined_gs() self._check_user_joined_gs()
await self._seeder.seed()
self._validate_init_time() self._validate_init_time()
self._logger.trace(__name__, f"Module {type(self)} stopped") self._logger.trace(__name__, f"Module {type(self)} stopped")

View File

@ -1,4 +1,5 @@
import discord import discord
from cpl_core.database.context import DatabaseContextABC
from cpl_discord.container import Guild from cpl_discord.container import Guild
from cpl_discord.service import DiscordBotServiceABC from cpl_discord.service import DiscordBotServiceABC
from discord import Permissions, Colour from discord import Permissions, Colour
@ -21,6 +22,7 @@ class LevelSeeder(DataSeederABC):
level_repo: LevelRepositoryService, level_repo: LevelRepositoryService,
servers: ServerRepositoryABC, servers: ServerRepositoryABC,
level: LevelService, level: LevelService,
db: DatabaseContextABC,
bot: DiscordBotServiceABC, bot: DiscordBotServiceABC,
): ):
DataSeederABC.__init__(self) DataSeederABC.__init__(self)
@ -29,6 +31,7 @@ class LevelSeeder(DataSeederABC):
self._levels = level_repo self._levels = level_repo
self._servers = servers self._servers = servers
self._level = level self._level = level
self._db = db
self._bot = bot self._bot = bot
self._level_header = levels.level_header self._level_header = levels.level_header
@ -51,6 +54,7 @@ class LevelSeeder(DataSeederABC):
if levels is None or levels.where(lambda l: l.name == level.name).first_or_default() is None: if levels is None or levels.where(lambda l: l.name == level.name).first_or_default() is None:
self._levels.add_level(level) self._levels.add_level(level)
self._logger.debug(__name__, f"Saved level {level.name}") self._logger.debug(__name__, f"Saved level {level.name}")
self._db.save_changes()
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