2025-04-29 17:24:07 +08:00
|
|
|
|
import asyncio
|
2025-06-02 21:43:27 +08:00
|
|
|
|
import argparse
|
2024-11-16 17:57:39 +08:00
|
|
|
|
# LangBot 终端启动入口
|
2024-02-29 11:10:30 +00:00
|
|
|
|
# 在此层级解决依赖项检查。
|
2024-11-16 17:57:39 +08:00
|
|
|
|
# LangBot/main.py
|
2024-01-23 22:28:30 +08:00
|
|
|
|
|
2024-01-27 00:05:55 +08:00
|
|
|
|
asciiart = r"""
|
2024-11-16 12:40:57 +08:00
|
|
|
|
_ ___ _
|
|
|
|
|
|
| | __ _ _ _ __ _| _ ) ___| |_
|
|
|
|
|
|
| |__/ _` | ' \/ _` | _ \/ _ \ _|
|
|
|
|
|
|
|____\__,_|_||_\__, |___/\___/\__|
|
|
|
|
|
|
|___/
|
|
|
|
|
|
|
2025-07-07 19:00:55 +08:00
|
|
|
|
⭐️ Open Source 开源地址: https://github.com/langbot-app/LangBot
|
2025-05-15 10:40:36 +08:00
|
|
|
|
📖 Documentation 文档地址: https://docs.langbot.app
|
2024-01-27 00:05:55 +08:00
|
|
|
|
"""
|
2024-01-23 22:28:30 +08:00
|
|
|
|
|
2024-02-29 11:10:30 +00:00
|
|
|
|
|
2024-10-11 22:27:53 +08:00
|
|
|
|
async def main_entry(loop: asyncio.AbstractEventLoop):
|
2025-06-02 21:43:27 +08:00
|
|
|
|
parser = argparse.ArgumentParser(description='LangBot')
|
2025-09-30 21:07:15 +08:00
|
|
|
|
parser.add_argument(
|
|
|
|
|
|
'--standalone-runtime',
|
|
|
|
|
|
action='store_true',
|
|
|
|
|
|
help='Use standalone plugin runtime / 使用独立插件运行时',
|
|
|
|
|
|
default=False,
|
|
|
|
|
|
)
|
|
|
|
|
|
parser.add_argument('--debug', action='store_true', help='Debug mode / 调试模式', default=False)
|
2025-06-02 21:43:27 +08:00
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
2025-08-23 23:03:32 +08:00
|
|
|
|
if args.standalone_runtime:
|
|
|
|
|
|
from pkg.utils import platform
|
|
|
|
|
|
|
|
|
|
|
|
platform.standalone_runtime = True
|
|
|
|
|
|
|
2025-09-30 21:07:15 +08:00
|
|
|
|
if args.debug:
|
|
|
|
|
|
from pkg.utils import constants
|
|
|
|
|
|
|
|
|
|
|
|
constants.debug_mode = True
|
|
|
|
|
|
|
2024-01-27 00:05:55 +08:00
|
|
|
|
print(asciiart)
|
|
|
|
|
|
|
2024-02-29 11:10:30 +00:00
|
|
|
|
import sys
|
|
|
|
|
|
|
2024-03-02 14:57:55 +08:00
|
|
|
|
# 检查依赖
|
|
|
|
|
|
|
2024-02-29 11:10:30 +00:00
|
|
|
|
from pkg.core.bootutils import deps
|
|
|
|
|
|
|
|
|
|
|
|
missing_deps = await deps.check_deps()
|
|
|
|
|
|
|
|
|
|
|
|
if missing_deps:
|
2025-04-29 17:24:07 +08:00
|
|
|
|
print('以下依赖包未安装,将自动安装,请完成后重启程序:')
|
2025-05-15 10:40:36 +08:00
|
|
|
|
print(
|
|
|
|
|
|
'These dependencies are missing, they will be installed automatically, please restart the program after completion:'
|
|
|
|
|
|
)
|
2024-02-29 11:10:30 +00:00
|
|
|
|
for dep in missing_deps:
|
2025-04-29 17:24:07 +08:00
|
|
|
|
print('-', dep)
|
2024-02-29 11:10:30 +00:00
|
|
|
|
await deps.install_deps(missing_deps)
|
2025-04-29 17:24:07 +08:00
|
|
|
|
print('已自动安装缺失的依赖包,请重启程序。')
|
2025-05-15 10:40:36 +08:00
|
|
|
|
print('The missing dependencies have been installed automatically, please restart the program.')
|
2024-02-29 11:10:30 +00:00
|
|
|
|
sys.exit(0)
|
2025-04-29 17:24:07 +08:00
|
|
|
|
|
2025-06-15 22:04:31 +08:00
|
|
|
|
# # 检查pydantic版本,如果没有 pydantic.v1,则把 pydantic 映射为 v1
|
|
|
|
|
|
# import pydantic.version
|
2025-04-29 17:24:07 +08:00
|
|
|
|
|
2025-06-15 22:04:31 +08:00
|
|
|
|
# if pydantic.version.VERSION < '2.0':
|
|
|
|
|
|
# import pydantic
|
2025-04-29 17:24:07 +08:00
|
|
|
|
|
2025-06-15 22:04:31 +08:00
|
|
|
|
# sys.modules['pydantic.v1'] = pydantic
|
2024-11-22 23:37:46 +08:00
|
|
|
|
|
2024-03-02 14:57:55 +08:00
|
|
|
|
# 检查配置文件
|
2024-03-14 16:00:22 +08:00
|
|
|
|
|
2024-03-02 14:57:55 +08:00
|
|
|
|
from pkg.core.bootutils import files
|
|
|
|
|
|
|
|
|
|
|
|
generated_files = await files.generate_files()
|
|
|
|
|
|
|
|
|
|
|
|
if generated_files:
|
2025-04-29 17:24:07 +08:00
|
|
|
|
print('以下文件不存在,已自动生成:')
|
2025-05-15 10:40:36 +08:00
|
|
|
|
print('Following files do not exist and have been automatically generated:')
|
2024-03-02 14:57:55 +08:00
|
|
|
|
for file in generated_files:
|
2025-04-29 17:24:07 +08:00
|
|
|
|
print('-', file)
|
2024-03-02 14:57:55 +08:00
|
|
|
|
|
2024-01-27 00:05:55 +08:00
|
|
|
|
from pkg.core import boot
|
2025-04-29 17:24:07 +08:00
|
|
|
|
|
2024-10-11 22:27:53 +08:00
|
|
|
|
await boot.main(loop)
|
2024-02-29 11:10:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2024-03-30 21:28:42 +08:00
|
|
|
|
import os
|
2024-10-22 18:17:09 +08:00
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
# 必须大于 3.10.1
|
|
|
|
|
|
if sys.version_info < (3, 10, 1):
|
2025-04-29 17:24:07 +08:00
|
|
|
|
print('需要 Python 3.10.1 及以上版本,当前 Python 版本为:', sys.version)
|
|
|
|
|
|
input('按任意键退出...')
|
2025-05-15 10:40:36 +08:00
|
|
|
|
print('Your Python version is not supported. Please exit the program by pressing any key.')
|
2024-10-22 18:17:09 +08:00
|
|
|
|
exit(1)
|
2024-03-30 21:28:42 +08:00
|
|
|
|
|
2025-05-15 10:40:36 +08:00
|
|
|
|
# Check if the current directory is the LangBot project root directory
|
2024-03-30 21:34:22 +08:00
|
|
|
|
invalid_pwd = False
|
|
|
|
|
|
|
|
|
|
|
|
if not os.path.exists('main.py'):
|
|
|
|
|
|
invalid_pwd = True
|
|
|
|
|
|
else:
|
|
|
|
|
|
with open('main.py', 'r', encoding='utf-8') as f:
|
|
|
|
|
|
content = f.read()
|
2025-04-29 17:24:07 +08:00
|
|
|
|
if 'LangBot/main.py' not in content:
|
2024-03-30 21:34:22 +08:00
|
|
|
|
invalid_pwd = True
|
|
|
|
|
|
if invalid_pwd:
|
2025-04-29 17:24:07 +08:00
|
|
|
|
print('请在 LangBot 项目根目录下以命令形式运行此程序。')
|
|
|
|
|
|
input('按任意键退出...')
|
2025-05-15 10:40:36 +08:00
|
|
|
|
print('Please run this program in the LangBot project root directory in command form.')
|
|
|
|
|
|
print('Press any key to exit...')
|
2024-10-11 22:27:53 +08:00
|
|
|
|
exit(1)
|
2024-03-30 21:34:22 +08:00
|
|
|
|
|
2024-10-11 22:27:53 +08:00
|
|
|
|
loop = asyncio.new_event_loop()
|
2024-02-29 11:10:30 +00:00
|
|
|
|
|
2024-10-11 22:27:53 +08:00
|
|
|
|
loop.run_until_complete(main_entry(loop))
|