Spaces:
Runtime error
Runtime error
Rename config.pt to config.py
Browse files
config.pt
DELETED
|
File without changes
|
config.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# filename: config.py
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import re
|
| 5 |
+
from dotenv import load_dotenv
|
| 6 |
+
|
| 7 |
+
# Load environment variables from a .env file for local development
|
| 8 |
+
# In production (like Docker/Hugging Face), these will be set directly.
|
| 9 |
+
load_dotenv()
|
| 10 |
+
|
| 11 |
+
# --- Helper function to cast environment variables ---
|
| 12 |
+
def get_env(key, default=None, cast_to=str):
|
| 13 |
+
"""Fetches an environment variable and casts it to a specified type."""
|
| 14 |
+
value = os.getenv(key, default)
|
| 15 |
+
if value is not None:
|
| 16 |
+
try:
|
| 17 |
+
# Handle boolean strings explicitly
|
| 18 |
+
if cast_to == bool:
|
| 19 |
+
return value.lower() in ('true', '1', 't', 'y', 'yes')
|
| 20 |
+
return cast_to(value)
|
| 21 |
+
except (ValueError, TypeError):
|
| 22 |
+
return default
|
| 23 |
+
return default
|
| 24 |
+
|
| 25 |
+
# --- Telegram Credentials (Mandatory) ---
|
| 26 |
+
API_ID = get_env("API_ID", cast_to=int)
|
| 27 |
+
API_HASH = get_env("API_HASH")
|
| 28 |
+
BOT_TOKEN = get_env("BOT_TOKEN")
|
| 29 |
+
OWNER_ID = get_env("OWNER_ID", cast_to=int)
|
| 30 |
+
|
| 31 |
+
if not all([API_ID, API_HASH, BOT_TOKEN, OWNER_ID]):
|
| 32 |
+
raise ValueError("Error: One or more mandatory Telegram credentials are not set in the environment.")
|
| 33 |
+
|
| 34 |
+
# --- Database Configuration (Mandatory) ---
|
| 35 |
+
# This logic automatically finds all MONGODB_URL_n secrets you've set.
|
| 36 |
+
mongo_vars = {}
|
| 37 |
+
for key, value in os.environ.items():
|
| 38 |
+
if match := re.match(r"MONGODB_URL_(\d+)", key):
|
| 39 |
+
if value:
|
| 40 |
+
mongo_vars[int(match.group(1))] = value
|
| 41 |
+
|
| 42 |
+
# Sort the found URLs by their number (1, 2, 3...) to create the final list
|
| 43 |
+
MONGODB_URIS = [mongo_vars[key] for key in sorted(mongo_vars.keys())]
|
| 44 |
+
|
| 45 |
+
if not MONGODB_URIS:
|
| 46 |
+
raise ValueError("Error: No MONGODB_URL_<n> environment variables found. Please set at least MONGODB_URL_1.")
|
| 47 |
+
|
| 48 |
+
# --- Bot Functionality (Mandatory) ---
|
| 49 |
+
TERABOX_WORKER_URL = get_env("TERABOX_WORKER_URL")
|
| 50 |
+
if not TERABOX_WORKER_URL:
|
| 51 |
+
raise ValueError("Error: TERABOX_WORKER_URL is not set.")
|
| 52 |
+
|
| 53 |
+
# --- Bot Features (Optional) ---
|
| 54 |
+
FORCE_SUB_CHANNEL_USERNAME = get_env("FORCE_SUB_CHANNEL_USERNAME")
|
| 55 |
+
BACKUP_CHANNEL_ID = get_env("BACKUP_CHANNEL_ID", cast_to=int)
|
| 56 |
+
|
| 57 |
+
# --- Performance, Limits & Toggles ---
|
| 58 |
+
PREMIUM_WORKERS = get_env("PREMIUM_WORKERS", 1, cast_to=int)
|
| 59 |
+
FREE_WORKERS = get_env("FREE_WORKERS", 1, cast_to=int)
|
| 60 |
+
|
| 61 |
+
_free_limit_mb = get_env("FREE_USER_FILE_SIZE_LIMIT", 50, cast_to=int)
|
| 62 |
+
FREE_USER_FILE_SIZE_LIMIT_BYTES = _free_limit_mb * 1024 * 1024
|
| 63 |
+
|
| 64 |
+
# Toggle for enabling FFMPEG features like thumbnailing and remuxing
|
| 65 |
+
ENABLE_FFMPEG = get_env("ENABLE_FFMPEG", True, cast_to=bool)
|