Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref: fix some typing errors #42

Merged
merged 2 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
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
14 changes: 8 additions & 6 deletions somnus/discord_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down
11 changes: 0 additions & 11 deletions somnus/logic/stop.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import asyncio

from pexpect import pxssh

from somnus.config import Config, CONFIG
Expand Down Expand Up @@ -86,12 +84,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())
7 changes: 7 additions & 0 deletions somnus/logic/world_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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:
Expand Down
Loading