Add ad support to config.py and fix \\n handling in replies
Build and Push (dev) / build (push) Successful in 3m13s

This commit is contained in:
2026-09-03 16:09:28 +00:00
parent a488a08cb9
commit 6d6a2e5534
+26
View File
@@ -33,6 +33,8 @@ class Config:
else: else:
options = [line] options = [line]
# Convert literal \n to actual newlines
options = [opt.replace("\\n", "\n") for opt in options]
reply_lines.append(options) reply_lines.append(options)
return reply_lines if reply_lines else default_replies return reply_lines if reply_lines else default_replies
@@ -40,6 +42,19 @@ class Config:
except FileNotFoundError: except FileNotFoundError:
return default_replies return default_replies
def _load_ads(self, file_path: str = "storage/ads.txt"):
"""Load ads from file, one ad per file (can be multi-line)"""
try:
with open(file_path, "r", encoding="utf-8") as f:
ad_content = f.read().strip()
if ad_content:
# Convert literal \n to actual newlines
return ad_content.replace("\\n", "\n")
return None
except FileNotFoundError:
logger.warning(f"Ad file {file_path} not found")
return None
def _load_captcha(self, file_path: str = "storage/captcha.txt"): def _load_captcha(self, file_path: str = "storage/captcha.txt"):
default_captcha = ( default_captcha = (
f"[CENTER][B]Напишите ответ:[/B]\n" f"[CENTER][B]Напишите ответ:[/B]\n"
@@ -138,6 +153,14 @@ class Config:
"ENABLE_CAPTCHA установлен, но CAPTCHA_ANSWER не задан" "ENABLE_CAPTCHA установлен, но CAPTCHA_ANSWER не задан"
) )
# Ads
enable_ads = (
os.getenv(key="ENABLE_ADS", default="false")
).lower() == "true"
ads_probability = max(
0.0, min(1.0, float(os.getenv(key="ADS_PROBABILITY", default=0.3)))
) # Clamp between 0.0 and 1.0
proxy_telegram = ( proxy_telegram = (
os.getenv(key="PROXY_TELEGRAM", default="false") os.getenv(key="PROXY_TELEGRAM", default="false")
).lower() == "true" ).lower() == "true"
@@ -296,6 +319,9 @@ class Config:
"enable_captcha": enable_captcha, "enable_captcha": enable_captcha,
"captcha_answer": captcha_answer, "captcha_answer": captcha_answer,
"captcha_check_interval": captcha_check_interval, "captcha_check_interval": captcha_check_interval,
# Ads
"enable_ads": enable_ads,
"ads_probability": ads_probability,
# Proxy # Proxy
"proxy_telegram": proxy_telegram, "proxy_telegram": proxy_telegram,
"proxy_lolz": proxy_lolz, "proxy_lolz": proxy_lolz,