mirror of
https://github.com/yshtcn/DiaryAssistant_bot.git
synced 2025-12-15 18:50:24 +08:00
- 把代理配置添加到配置文件中
This commit is contained in:
parent
b402c62227
commit
a5415f676e
@ -5,17 +5,11 @@ from datetime import datetime
|
|||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
|
|
||||||
# 配置代理
|
|
||||||
proxies = {
|
proxies = None
|
||||||
'http': 'http://127.0.0.1:7890',
|
|
||||||
'https': 'http://127.0.0.1:7890'
|
|
||||||
}
|
|
||||||
|
|
||||||
TOKEN = None
|
TOKEN = None
|
||||||
|
|
||||||
# 示范Token
|
|
||||||
example_token = "Your_Token_Here"
|
|
||||||
|
|
||||||
# 定义配置文件名
|
# 定义配置文件名
|
||||||
config_filename = "bot_config.json"
|
config_filename = "bot_config.json"
|
||||||
|
|
||||||
@ -27,19 +21,38 @@ if os.path.exists(config_path):
|
|||||||
with open(config_path, 'r') as f:
|
with open(config_path, 'r') as f:
|
||||||
config = json.load(f)
|
config = json.load(f)
|
||||||
TOKEN = config.get("TOKEN", "")
|
TOKEN = config.get("TOKEN", "")
|
||||||
|
proxies_config = config.get("PROXIES", {})
|
||||||
|
|
||||||
# 检查Token是否已设置
|
# 检查Token是否已设置
|
||||||
if TOKEN == example_token:
|
if not TOKEN:
|
||||||
print("Please update your bot token in the config file.")
|
print("Please set your bot token in the config file.")
|
||||||
exit(1)
|
exit(1)
|
||||||
else:
|
else:
|
||||||
# 如果配置文件不存在,则创建一个新的配置文件并写入示范Token
|
# 如果配置文件不存在,则创建一个新的配置文件并写入示范Token和示范代理
|
||||||
config = {"TOKEN": example_token}
|
config = {
|
||||||
|
"TOKEN": "Your_Token_Here",
|
||||||
|
"PROXIES": {
|
||||||
|
"http": "http://127.0.0.1:7890",
|
||||||
|
"https": "http://127.0.0.1:7890"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# 将config对象转换为格式化的JSON字符串
|
||||||
|
config_str = json.dumps(config, indent=4)
|
||||||
|
|
||||||
with open(config_path, 'w') as f:
|
with open(config_path, 'w') as f:
|
||||||
json.dump(config, f)
|
f.write(config_str)
|
||||||
print(f"Config file created at {config_path}. Please update your bot token.")
|
print(f"Config file created at {config_path}. Please set your bot token.")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
# 设置代理
|
||||||
|
if proxies_config:
|
||||||
|
proxies = {
|
||||||
|
'http': proxies_config.get('http', ''),
|
||||||
|
'https': proxies_config.get('https', '')
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
proxies = None
|
||||||
|
|
||||||
URL = f"https://api.telegram.org/bot{TOKEN}/"
|
URL = f"https://api.telegram.org/bot{TOKEN}/"
|
||||||
|
|
||||||
# 尝试从文件中加载已有数据
|
# 尝试从文件中加载已有数据
|
||||||
@ -152,7 +165,7 @@ def process_message_queue():
|
|||||||
|
|
||||||
# 主程序逻辑
|
# 主程序逻辑
|
||||||
def main():
|
def main():
|
||||||
print("Program started") # Debugging line
|
print("Program started")
|
||||||
last_update_id = None
|
last_update_id = None
|
||||||
while True:
|
while True:
|
||||||
print("Process message queue...")
|
print("Process message queue...")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user