Skip to content
This repository was archived by the owner on May 25, 2026. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions somnus/discord_provider/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@


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
Expand Down Expand Up @@ -88,10 +86,6 @@

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()


Expand Down Expand Up @@ -135,6 +129,8 @@

@tree.command(name="start", description=LH("commands.start.description"))
async def start_server_command(ctx: discord.Interaction) -> None:
global inactivity_seconds

Check failure on line 132 in somnus/discord_provider/main.py

View workflow job for this annotation

GitHub Actions / Ruff Lint

Ruff (PLW0603)

somnus/discord_provider/main.py:132:12: PLW0603 Using the global statement to update `inactivity_seconds` is discouraged

world_config = await world_selector.get_world_selector_config()

action_props = ActionWrapperProperties(
Expand All @@ -149,6 +145,11 @@
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"))
Expand Down Expand Up @@ -211,7 +212,7 @@


@tree.command(name="edit_world", description=LH("commands.edit_world.description"))
async def edit_world_command( # noqa: PLR0913

Check failure on line 215 in somnus/discord_provider/main.py

View workflow job for this annotation

GitHub Actions / Ruff Lint

Ruff (RUF100)

somnus/discord_provider/main.py:215:32: RUF100 Unused `noqa` directive (unused: `PLR0913`)
ctx: discord.Interaction,
editing_world_name: str,
new_display_name: str | None = None,
Expand Down Expand Up @@ -738,8 +739,12 @@
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()
Expand Down Expand Up @@ -824,7 +829,10 @@

@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:
Expand Down
Loading