From bba87d7685d62e20051cfe402311cd1f0981c3cd Mon Sep 17 00:00:00 2001 From: 2mal3 <56305732+2mal3@users.noreply.github.com> Date: Mon, 24 Feb 2025 10:03:33 +0100 Subject: [PATCH 1/2] ref: fix some typing errors --- somnus/discord_provider.py | 14 ++++++++------ somnus/logic/stop.py | 9 --------- somnus/logic/world_selector.py | 7 +++++++ 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/somnus/discord_provider.py b/somnus/discord_provider.py index e235ddf..e19a786 100644 --- a/somnus/discord_provider.py +++ b/somnus/discord_provider.py @@ -722,7 +722,7 @@ async def _get_discord_activity( if activity_str == "Game": return discord.Game(name=text) elif activity_str == "Streaming": - return discord.Streaming(name=text) + return discord.Streaming(name=text, url="") elif activity_str == "Listening": return discord.Activity(type=discord.ActivityType.listening, name=text) elif activity_str == "Watching": @@ -755,10 +755,12 @@ async def _stop_inactivity(): log.error("DISCORD_STATUS_CHANNEL_ID in .env not correct. Automatic shutdown due to inactivity not possible!") return False channel = bot.get_channel(CONFIG.DISCORD_STATUS_CHANNEL_ID) + if not channel or not isinstance(channel, discord.TextChannel): + raise TypeError("Could not get channel from Discord!") log.info("Send information message for shutdown due to inactivity ...") - message = await _inactivity_shutdown_verification(channel) - if message is not False: + message, player_confirmed_stop = await _inactivity_shutdown_verification(channel) + if player_confirmed_stop: log.info("Stopping due to inactivity ...") if not await _check_if_busy(): inactvity_seconds = CONFIG.INACTIVITY_SHUTDOWN_MINUTES * 60 @@ -794,7 +796,7 @@ async def _stop_inactivity(): await _no_longer_busy() -async def _inactivity_shutdown_verification(channel: discord.TextChannel) -> discord.Message | bool: +async def _inactivity_shutdown_verification(channel: discord.TextChannel) -> tuple[discord.Message, bool]: result_future = asyncio.Future() cancel_button = discord.ui.Button(label=LH.t("other.inactivity_shutdown.cancel"), style=discord.ButtonStyle.green) @@ -836,9 +838,9 @@ async def cancel_callback(interaction: discord.Interaction): finally: result = await result_future if result: - return message + return message, True else: - return False + return message, False async def _get_formatted_world_info_string(world: world_selector.WorldSelectorWorld): diff --git a/somnus/logic/stop.py b/somnus/logic/stop.py index a71aeee..f573317 100644 --- a/somnus/logic/stop.py +++ b/somnus/logic/stop.py @@ -86,12 +86,3 @@ async def _stop_mc_server(ssh: pxssh.pxssh, config: Config): yield return yield - - -async def main(): - async for _ in stop_server(): - pass - - -if __name__ == "__main__": - asyncio.run(main()) diff --git a/somnus/logic/world_selector.py b/somnus/logic/world_selector.py index f467e7f..49efe5f 100644 --- a/somnus/logic/world_selector.py +++ b/somnus/logic/world_selector.py @@ -91,6 +91,11 @@ async def select_new_world(new_world_name): async def edit_new_world( editing_world_name, new_display_name, start_cmd, start_cmd_sudo, visible ) -> WorldSelectorWorld: + """ + Raises + UserInputError: If the world to edit doesn't exist + """ + world_selector_config = await get_world_selector_config() for i, world in enumerate(world_selector_config.worlds): @@ -109,6 +114,8 @@ async def edit_new_world( await _save_world_selector_config(world_selector_config) return world_selector_config.worlds[i] + raise UserInputError(f"World '{editing_world_name}' not found") + async def try_delete_world(display_name: str): try: From cba27cd89e3bfca0b0970dd470984c5d14695dae Mon Sep 17 00:00:00 2001 From: 2mal3 <56305732+2mal3@users.noreply.github.com> Date: Mon, 24 Feb 2025 10:06:39 +0100 Subject: [PATCH 2/2] ref(stop): removed now unneeded import --- somnus/logic/stop.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/somnus/logic/stop.py b/somnus/logic/stop.py index f573317..aaf168b 100644 --- a/somnus/logic/stop.py +++ b/somnus/logic/stop.py @@ -1,5 +1,3 @@ -import asyncio - from pexpect import pxssh from somnus.config import Config, CONFIG