From fc83ffc3701fa438f8c9a1efedd58f54022d11fa Mon Sep 17 00:00:00 2001 From: GiuPic <47813665+GiuPic@users.noreply.github.com> Date: Tue, 13 May 2025 13:21:29 +0200 Subject: [PATCH] Fix telegram bot (issues #305 bug) (#316) * fix create config.json * fix messagge telegram_bot option 0 (Streamingcommunity) --- .../Api/Site/streamingcommunity/__init__.py | 16 +++++++++++++++- StreamingCommunity/Util/config_json.py | 9 +++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/StreamingCommunity/Api/Site/streamingcommunity/__init__.py b/StreamingCommunity/Api/Site/streamingcommunity/__init__.py index 6809642..160dbb6 100644 --- a/StreamingCommunity/Api/Site/streamingcommunity/__init__.py +++ b/StreamingCommunity/Api/Site/streamingcommunity/__init__.py @@ -97,7 +97,21 @@ def search(string_to_search: str = None, get_onlyDatabase: bool = False, direct_ return if string_to_search is None: - string_to_search = msg.ask(f"\n[purple]Insert a word to search in [green]{site_constant.SITE_NAME}").strip() + if site_constant.TELEGRAM_BOT: + bot = get_bot_instance() + string_to_search = bot.ask( + "key_search", + f"Enter the search term\nor type 'back' to return to the menu: ", + None + ) + + if string_to_search == 'back': + + # Restart the script + subprocess.Popen([sys.executable] + sys.argv) + sys.exit() + else: + string_to_search = msg.ask(f"\n[purple]Insert a word to search in [green]{site_constant.SITE_NAME}").strip() # Search on database len_database = title_search(string_to_search) diff --git a/StreamingCommunity/Util/config_json.py b/StreamingCommunity/Util/config_json.py index 9bee73e..bea1edc 100644 --- a/StreamingCommunity/Util/config_json.py +++ b/StreamingCommunity/Util/config_json.py @@ -36,8 +36,13 @@ class ConfigManager: base_path = os.path.dirname(sys.executable) else: - # Use the current directory where the script is executed - base_path = os.getcwd() + + # Get the actual path of the module file + current_file_path = os.path.abspath(__file__) + # Navigate upwards to find the project root + # Assuming this file is in a package structure like StreamingCommunity/Util/config_json.py + # We need to go up 2 levels to reach the project root + base_path = os.path.dirname(os.path.dirname(os.path.dirname(current_file_path))) # Initialize file paths self.file_path = os.path.join(base_path, file_name)