Add ad support to config.py and fix \\n handling in replies
Build and Push (dev) / build (push) Successful in 3m13s
Build and Push (dev) / build (push) Successful in 3m13s
This commit is contained in:
@@ -33,6 +33,8 @@ class Config:
|
||||
else:
|
||||
options = [line]
|
||||
|
||||
# Convert literal \n to actual newlines
|
||||
options = [opt.replace("\\n", "\n") for opt in options]
|
||||
reply_lines.append(options)
|
||||
|
||||
return reply_lines if reply_lines else default_replies
|
||||
@@ -40,6 +42,19 @@ class Config:
|
||||
except FileNotFoundError:
|
||||
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"):
|
||||
default_captcha = (
|
||||
f"[CENTER][B]Напишите ответ:[/B]\n"
|
||||
@@ -138,6 +153,14 @@ class Config:
|
||||
"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 = (
|
||||
os.getenv(key="PROXY_TELEGRAM", default="false")
|
||||
).lower() == "true"
|
||||
@@ -296,6 +319,9 @@ class Config:
|
||||
"enable_captcha": enable_captcha,
|
||||
"captcha_answer": captcha_answer,
|
||||
"captcha_check_interval": captcha_check_interval,
|
||||
# Ads
|
||||
"enable_ads": enable_ads,
|
||||
"ads_probability": ads_probability,
|
||||
# Proxy
|
||||
"proxy_telegram": proxy_telegram,
|
||||
"proxy_lolz": proxy_lolz,
|
||||
|
||||
Reference in New Issue
Block a user