From dc5efa2b47967a3099623fb9a5a5aae7d716c726 Mon Sep 17 00:00:00 2001 From: Jonathan Hite Date: Fri, 7 Feb 2025 23:08:04 -0500 Subject: [PATCH] fixed an issue with exiting midgame --- command_handlers.py | 2 +- message_processing.py | 12 ++++++++---- server.py | 6 ++++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/command_handlers.py b/command_handlers.py index def5ec7..5d91251 100644 --- a/command_handlers.py +++ b/command_handlers.py @@ -949,4 +949,4 @@ def process_game_choice(sender_id, message, interface, state): present_story_segment(sender_id, interface, state) except ValueError: - send_message("Invalid input. Please enter a valid number.", sender_id, interface) + send_message("Invalid input. Please enter a valid number.", sender_id, interface) \ No newline at end of file diff --git a/message_processing.py b/message_processing.py index 7288806..7a68a81 100644 --- a/message_processing.py +++ b/message_processing.py @@ -104,14 +104,19 @@ def process_message(sender_id, message, interface, is_sync_message=False): channel_name, channel_url = parts[1], parts[2] add_channel(channel_name, channel_url) else: - # ✅ **Corrected IN_GAME Handling** + # ✅ **Fix: Ensure Games Menu Loads After Exiting a Game** if state and state['command'] == 'IN_GAME': - message_lower = message.lower().strip() + logging.debug(f"🎮 User {sender_id} is in-game, processing game command...") - # Always check if the user wants to exit if message_lower == "x": + logging.debug(f"❌ User {sender_id} exited the game. Sending exit message...") send_message(f"Exiting '{state['game']}'... Returning to Games Menu.", sender_id, interface) update_user_state(sender_id, {'command': 'GAMES', 'step': 1}) + + logging.debug(f"🚀 Calling handle_games_command() for user {sender_id} after exit.") + handle_games_command(sender_id, interface) + logging.debug(f"✅ handle_games_command() execution completed for user {sender_id}!") + return # Otherwise, process the game choice @@ -211,7 +216,6 @@ def process_message(sender_id, message, interface, is_sync_message=False): - def on_receive(packet, interface): try: if 'decoded' in packet and packet['decoded']['portnum'] == 'TEXT_MESSAGE_APP': diff --git a/server.py b/server.py index f551978..3aa7839 100644 --- a/server.py +++ b/server.py @@ -16,9 +16,11 @@ import logging import time import sys import io +import locale -# Reconfigure stdout to use UTF-8 encoding -sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8') +# Apply UTF-8 fix only if needed +if "utf" not in locale.getpreferredencoding().lower(): + sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8') from config_init import initialize_config, get_interface, init_cli_parser, merge_config from db_operations import initialize_database