yangtb24 commited on
Commit
5298a55
·
verified ·
1 Parent(s): c1ed78b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -7,12 +7,11 @@ import asyncio
7
 
8
  app = Flask(__name__)
9
 
10
- # 从环境变量中获取配置
11
  TELEGRAM_BOT_TOKEN = os.environ.get('TELEGRAM_BOT_TOKEN')
12
  AI_API_ENDPOINT = os.environ.get('AI_API_ENDPOINT')
13
  AI_API_KEY = os.environ.get('AI_API_KEY')
14
  AI_MODEL = os.environ.get('AI_MODEL')
15
- PHP_PROXY_URL = os.environ.get('PHP_PROXY_URL') # 代理地址
16
 
17
  if not all([TELEGRAM_BOT_TOKEN, AI_API_ENDPOINT, AI_API_KEY, AI_MODEL]):
18
  raise ValueError("请设置所有必要的环境变量")
@@ -49,6 +48,7 @@ BOT_COMMANDS = [
49
  {"command": "resetuser", "description": "重置你的个人设置"},
50
  {"command": "promat", "description": "切换提示词,例如: /promat 0, 1, 2"},
51
  {"command": "getpromat", "description": "获取当前使用的提示词索引"},
 
52
  ]
53
  BOT_USERNAME = 'zfs732_bot'
54
  DEFAULT_TEMP = 1.5
@@ -97,6 +97,7 @@ TOOL_DEFINITIONS = [
97
  },
98
  },
99
  ]
 
100
  class EventEmitter:
101
  def __init__(self, event_emitter=None):
102
  self.event_emitter = event_emitter
@@ -116,7 +117,7 @@ class EventEmitter:
116
 
117
  def make_telegram_request(method, data=None):
118
  url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/{method}"
119
- if PHP_PROXY_URL: # 使用代理
120
  url = f"{PHP_PROXY_URL}{method}"
121
  headers = {'Content-Type': 'application/json'}
122
  if data:
@@ -135,7 +136,7 @@ def make_telegram_request(method, data=None):
135
  async def setBotCommands():
136
  delete_url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/deleteMyCommands"
137
  set_url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/setMyCommands"
138
- if PHP_PROXY_URL: # 使用代理
139
  delete_url = f"{PHP_PROXY_URL}deleteMyCommands"
140
  set_url = f"{PHP_PROXY_URL}setMyCommands"
141
 
@@ -505,7 +506,7 @@ async def handle_webhook():
505
  except Exception as e:
506
  import traceback
507
  print(f"请求解析失败: {e}")
508
- traceback.print_exc() # 打印详细的堆栈信息
509
  return jsonify({'status': 'error', 'message': str(e)}), 400
510
 
511
 
 
7
 
8
  app = Flask(__name__)
9
 
 
10
  TELEGRAM_BOT_TOKEN = os.environ.get('TELEGRAM_BOT_TOKEN')
11
  AI_API_ENDPOINT = os.environ.get('AI_API_ENDPOINT')
12
  AI_API_KEY = os.environ.get('AI_API_KEY')
13
  AI_MODEL = os.environ.get('AI_MODEL')
14
+ PHP_PROXY_URL = os.environ.get('PHP_PROXY_URL')
15
 
16
  if not all([TELEGRAM_BOT_TOKEN, AI_API_ENDPOINT, AI_API_KEY, AI_MODEL]):
17
  raise ValueError("请设置所有必要的环境变量")
 
48
  {"command": "resetuser", "description": "重置你的个人设置"},
49
  {"command": "promat", "description": "切换提示词,例如: /promat 0, 1, 2"},
50
  {"command": "getpromat", "description": "获取当前使用的提示词索引"},
51
+ {"command": "test", "description": "获取当前使用的提示词索引"},
52
  ]
53
  BOT_USERNAME = 'zfs732_bot'
54
  DEFAULT_TEMP = 1.5
 
97
  },
98
  },
99
  ]
100
+
101
  class EventEmitter:
102
  def __init__(self, event_emitter=None):
103
  self.event_emitter = event_emitter
 
117
 
118
  def make_telegram_request(method, data=None):
119
  url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/{method}"
120
+ if PHP_PROXY_URL:
121
  url = f"{PHP_PROXY_URL}{method}"
122
  headers = {'Content-Type': 'application/json'}
123
  if data:
 
136
  async def setBotCommands():
137
  delete_url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/deleteMyCommands"
138
  set_url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/setMyCommands"
139
+ if PHP_PROXY_URL:
140
  delete_url = f"{PHP_PROXY_URL}deleteMyCommands"
141
  set_url = f"{PHP_PROXY_URL}setMyCommands"
142
 
 
506
  except Exception as e:
507
  import traceback
508
  print(f"请求解析失败: {e}")
509
+ traceback.print_exc()
510
  return jsonify({'status': 'error', 'message': str(e)}), 400
511
 
512