From eff127306a27d203bac2e97bd13f339c6bef2ccd Mon Sep 17 00:00:00 2001 From: 2mal3 <56305732+2mal3@users.noreply.github.com> Date: Sat, 18 Apr 2026 15:47:26 +0200 Subject: [PATCH 1/2] fix(discord_provider): update_players_online_status incorrectly started --- somnus/discord_provider/main.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/somnus/discord_provider/main.py b/somnus/discord_provider/main.py index 6503a85..c9a295e 100644 --- a/somnus/discord_provider/main.py +++ b/somnus/discord_provider/main.py @@ -42,8 +42,6 @@ class ActionWrapperProperties(BaseModel): async def action_wrapper(props: ActionWrapperProperties) -> None: - global inactivity_seconds # noqa: PLW0603 - if busy_provider.is_busy(): await props.ctx.response.send_message(LH("other.busy"), ephemeral=True) return @@ -88,10 +86,6 @@ async def action_wrapper(props: ActionWrapperProperties) -> None: finally: busy_provider.make_available() - if CONFIG.INACTIVITY_SHUTDOWN_MINUTES: - inactivity_seconds = CONFIG.INACTIVITY_SHUTDOWN_MINUTES * 60 - update_players_online_status.start() - log.info("Status Updater started!") await _update_bot_presence_and_inactivity() @@ -135,6 +129,8 @@ async def ping_command(ctx: discord.Interaction) -> None: @tree.command(name="start", description=LH("commands.start.description")) async def start_server_command(ctx: discord.Interaction) -> None: + global inactivity_seconds + world_config = await world_selector.get_world_selector_config() action_props = ActionWrapperProperties( @@ -149,6 +145,11 @@ async def start_server_command(ctx: discord.Interaction) -> None: await action_wrapper(action_props) except Exception: pass + else: + if CONFIG.INACTIVITY_SHUTDOWN_MINUTES: + inactivity_seconds = CONFIG.INACTIVITY_SHUTDOWN_MINUTES * 60 + update_players_online_status.start() + log.info("Status Updater started!") @tree.command(name="stop", description=LH("commands.stop.description")) From 6ab504ac890c2a7f9f6c25e50c76f3ae7d93a223 Mon Sep 17 00:00:00 2001 From: 2mal3 <56305732+2mal3@users.noreply.github.com> Date: Sat, 18 Apr 2026 16:14:47 +0200 Subject: [PATCH 2/2] chore(discord_provider): more stable error handling for inactivity --- somnus/discord_provider/main.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/somnus/discord_provider/main.py b/somnus/discord_provider/main.py index c9a295e..1bc9cab 100644 --- a/somnus/discord_provider/main.py +++ b/somnus/discord_provider/main.py @@ -739,8 +739,12 @@ async def _stop_inactivity() -> bool | None: activity = discord.Game(name=LH("status.text.stopping", args={"world_name": world_config.current_world})) await bot.change_presence(status=Status.idle, activity=activity) - async for _ in stop.stop_server(True, CONFIG): - pass + try: + async for _ in stop.stop_server(True, CONFIG): + pass + except Exception as e: + log.error("Failed to stop server during inactivity shutdown", exc_info=e) + await message.edit(content=LH("commands.stop.error.general", args={"e": e})) await _update_bot_presence_and_inactivity() await message.edit(content=LH("other.inactivity_shutdown.finished_msg")) busy_provider.make_available() @@ -825,7 +829,10 @@ async def _is_super_user(ctx: discord.Interaction, message: bool = True) -> bool @tasks.loop(seconds=10) async def update_players_online_status() -> None: - await _update_bot_presence_and_inactivity() + try: + await _update_bot_presence_and_inactivity() + except Exception as e: + log.error("Failed to update bot presence and inactivity", exc_info=e) def main(config: Config = CONFIG) -> None: