Merge branch 'MaiM-with-u:main-fix' into main-fix

This commit is contained in:
Corolin
2025-03-19 20:51:52 +08:00
committed by GitHub
63 changed files with 3704 additions and 3808 deletions

21
bot.py
View File

@@ -14,8 +14,6 @@ from nonebot.adapters.onebot.v11 import Adapter
import platform
from src.common.logger import get_module_logger
# 配置主程序日志格式
logger = get_module_logger("main_bot")
# 获取没有加载env时的环境变量
@@ -103,7 +101,6 @@ def load_env():
RuntimeError(f"ENVIRONMENT 配置错误,请检查 .env 文件中的 ENVIRONMENT 变量及对应 .env.{env} 是否存在")
def scan_provider(env_config: dict):
provider = {}
@@ -166,12 +163,13 @@ async def uvicorn_main():
uvicorn_server = server
await server.serve()
def check_eula():
eula_confirm_file = Path("eula.confirmed")
privacy_confirm_file = Path("privacy.confirmed")
eula_file = Path("EULA.md")
privacy_file = Path("PRIVACY.md")
eula_updated = True
eula_new_hash = None
privacy_updated = True
@@ -226,15 +224,15 @@ def check_eula():
print(f'输入"同意""confirmed"或设置环境变量"EULA_AGREE={eula_new_hash}""PRIVACY_AGREE={privacy_new_hash}"继续运行')
while True:
user_input = input().strip().lower()
if user_input in ['同意', 'confirmed']:
if user_input in ["同意", "confirmed"]:
# print("确认成功,继续运行")
# print(f"确认成功,继续运行{eula_updated} {privacy_updated}")
if eula_updated:
print(f"更新EULA确认文件{eula_new_hash}")
eula_confirm_file.write_text(eula_new_hash,encoding="utf-8")
eula_confirm_file.write_text(eula_new_hash, encoding="utf-8")
if privacy_updated:
print(f"更新隐私条款确认文件{privacy_new_hash}")
privacy_confirm_file.write_text(privacy_new_hash,encoding="utf-8")
privacy_confirm_file.write_text(privacy_new_hash, encoding="utf-8")
break
else:
print('请输入"同意""confirmed"以继续运行')
@@ -242,19 +240,20 @@ def check_eula():
elif eula_confirmed and privacy_confirmed:
return
def raw_main():
# 利用 TZ 环境变量设定程序工作的时区
# 仅保证行为一致,不依赖 localtime(),实际对生产环境几乎没有作用
if platform.system().lower() != "windows":
time.tzset()
check_eula()
print("检查EULA和隐私条款完成")
easter_egg()
init_config()
init_env()
load_env()
# load_logger()
env_config = {key: os.getenv(key) for key in os.environ}
@@ -286,7 +285,7 @@ if __name__ == "__main__":
app = nonebot.get_asgi()
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
try:
loop.run_until_complete(uvicorn_main())
except KeyboardInterrupt:
@@ -294,7 +293,7 @@ if __name__ == "__main__":
loop.run_until_complete(graceful_shutdown())
finally:
loop.close()
except Exception as e:
logger.error(f"主程序异常: {str(e)}")
if loop and not loop.is_closed():