yangtb24 commited on
Commit
cafed63
·
verified ·
1 Parent(s): 087c88d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -5
app.py CHANGED
@@ -12,13 +12,13 @@ from requests.auth import HTTPBasicAuth
12
  app = Flask(__name__)
13
 
14
  TELEGRAM_BOT_TOKEN = os.environ.get('TELEGRAM_BOT_TOKEN')
15
- AI_API_ENDPOINT = os.environ.get('AI_API_ENDPOINT')
16
- AI_API_KEY = os.environ.get('AI_API_KEY')
17
- AI_MODEL = os.environ.get('AI_MODEL')
18
  PHP_PROXY_URL = os.environ.get('PHP_PROXY_URL')
19
 
20
- if not all([TELEGRAM_BOT_TOKEN, AI_API_ENDPOINT, AI_API_KEY, AI_MODEL]):
21
- raise ValueError("请设置所有必要的环境变量")
22
 
23
  AI_API_HEADERS = {
24
  'Content-Type': 'application/json',
@@ -83,11 +83,26 @@ BAN_TRIGGER_PHRASES = [
83
  ]
84
  UNBAN_PHRASE = "close username"
85
 
 
86
  WEBDAV_URL = os.environ.get('WEBDAV_URL')
87
  WEBDAV_USERNAME = os.environ.get('WEBDAV_USERNAME')
88
  WEBDAV_PASSWORD = os.environ.get('WEBDAV_PASSWORD')
89
 
 
 
 
 
 
 
 
 
 
90
  def save_data_to_webdav():
 
 
 
 
 
91
  print(f"开始保存数据到WebDAV: {datetime.now()}")
92
  try:
93
  data = {
@@ -122,6 +137,11 @@ def save_data_to_webdav():
122
  def load_data_from_webdav():
123
  global chatHistories, GROUP_SETTINGS, USER_SETTINGS, USER_LAST_ACTIVE, GROUP_ACTIVE_USERS, GROUP_INFO, BANNED_USERS
124
 
 
 
 
 
 
125
  print(f"开始从WebDAV加载数据: {datetime.now()}")
126
  try:
127
  response = requests.get(f"{WEBDAV_URL}/tg_bot/bot_data.json",
@@ -155,8 +175,10 @@ def periodic_save():
155
  time.sleep(10)
156
  save_data_to_webdav()
157
 
 
158
  load_data_from_webdav()
159
 
 
160
  save_thread = threading.Thread(target=periodic_save)
161
  save_thread.daemon = True
162
  save_thread.start()
 
12
  app = Flask(__name__)
13
 
14
  TELEGRAM_BOT_TOKEN = os.environ.get('TELEGRAM_BOT_TOKEN')
15
+ AI_API_ENDPOINT = os.environ.get('AI_API_ENDPOINT', "https://yangtb24-sone-latest.hf.space/handsome/v1/chat/completions")
16
+ AI_API_KEY = os.environ.get('AI_API_KEY', "sk-handsome")
17
+ AI_MODEL = os.environ.get('AI_MODEL', "deepseek-ai/DeepSeek-V2.5")
18
  PHP_PROXY_URL = os.environ.get('PHP_PROXY_URL')
19
 
20
+ if not TELEGRAM_BOT_TOKEN:
21
+ raise ValueError("请设置 TELEGRAM_BOT_TOKEN 环境变量")
22
 
23
  AI_API_HEADERS = {
24
  'Content-Type': 'application/json',
 
83
  ]
84
  UNBAN_PHRASE = "close username"
85
 
86
+ # 获取 WebDAV 环境变量
87
  WEBDAV_URL = os.environ.get('WEBDAV_URL')
88
  WEBDAV_USERNAME = os.environ.get('WEBDAV_USERNAME')
89
  WEBDAV_PASSWORD = os.environ.get('WEBDAV_PASSWORD')
90
 
91
+ # 初始化数据结构 (这里假设这些变量已经定义,你需要根据你的实际代码进行调整)
92
+ chatHistories = {}
93
+ GROUP_SETTINGS = {}
94
+ USER_SETTINGS = {}
95
+ USER_LAST_ACTIVE = {}
96
+ GROUP_ACTIVE_USERS = {}
97
+ GROUP_INFO = {}
98
+ BANNED_USERS = {}
99
+
100
  def save_data_to_webdav():
101
+ # 检查是否有 WebDAV 配置
102
+ if not all([WEBDAV_URL, WEBDAV_USERNAME, WEBDAV_PASSWORD]):
103
+ print("WebDAV 配置不完整,跳过保存操作")
104
+ return
105
+
106
  print(f"开始保存数据到WebDAV: {datetime.now()}")
107
  try:
108
  data = {
 
137
  def load_data_from_webdav():
138
  global chatHistories, GROUP_SETTINGS, USER_SETTINGS, USER_LAST_ACTIVE, GROUP_ACTIVE_USERS, GROUP_INFO, BANNED_USERS
139
 
140
+ # 检查是否有 WebDAV 配置
141
+ if not all([WEBDAV_URL, WEBDAV_USERNAME, WEBDAV_PASSWORD]):
142
+ print("WebDAV 配置不完整,跳过加载操作")
143
+ return
144
+
145
  print(f"开始从WebDAV加载数据: {datetime.now()}")
146
  try:
147
  response = requests.get(f"{WEBDAV_URL}/tg_bot/bot_data.json",
 
175
  time.sleep(10)
176
  save_data_to_webdav()
177
 
178
+ # 初始加载数据
179
  load_data_from_webdav()
180
 
181
+ # 启动定时保存线程
182
  save_thread = threading.Thread(target=periodic_save)
183
  save_thread.daemon = True
184
  save_thread.start()