Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: HTTP API 重构 #790

Merged
merged 6 commits into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions bot.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
import sys


sys.path.append(os.getcwd())
from framework.accounts import account_manager

Expand Down Expand Up @@ -42,11 +41,6 @@

bots.append(start_task())

if constants.config.onebot:
logger.info("检测到 Onebot 配置,将启动 Onebot 模式……")
from framework.platforms.onebot_bot import start_task

bots.append(start_task())
if constants.config.telegram:
logger.info("检测到 telegram 配置,将启动 telegram bot 模式……")
from framework.platforms.telegram_bot import start_task
Expand All @@ -57,16 +51,24 @@
from framework.platforms.discord_bot import start_task

bots.append(start_task())
if constants.config.http:
logger.info("检测到 http 配置,将启动 http service 模式……")
from framework.platforms.http_service import start_task

bots.append(start_task())
if constants.config.wecom:
logger.info("检测到 Wecom 配置,将启动 Wecom Bot 模式……")
from framework.platforms.wecom_bot import start_task

bots.append(start_task())
async def setup_web_service():
from framework.platforms.onebot_bot import bot, start_http_app
from framework.platforms.http_service import route as routes_http
from framework.platforms.http_service_legacy import route as routes_http_legacy
routes_http(bot.server_app)
routes_http_legacy(bot.server_app)
logger.info("启动 HTTP API……")
app = await start_http_app()

if constants.config.wecom:
logger.info("检测到 Wecom 配置,将注册 Wecom 路由……")
from framework.platforms.wecom_bot import route as routes_wecom
routes_wecom(app)


bots.append(setup_web_service())

loop.run_until_complete(asyncio.gather(*bots))
loop.run_forever()
Loading