diff --git a/core/database/bot.py b/core/database/bot.py index 00a6c87b..7a48f5bf 100644 --- a/core/database/bot.py +++ b/core/database/bot.py @@ -2,9 +2,10 @@ from amiyabot.database import * from amiyabot.adapters.mirai import mirai_api_http from amiyabot.adapters.cqhttp import cq_http -from amiyabot.adapters.onebot11 import onebot11 -from amiyabot.adapters.onebot12 import onebot12 +from amiyabot.adapters.onebot.v11 import onebot11 +from amiyabot.adapters.onebot.v12 import onebot12 from amiyabot.adapters.comwechat import com_wechat +from amiyabot.adapters.test import test_instance from core.database import config, is_mysql from typing import Union @@ -70,6 +71,9 @@ def get_all_account(cls): http_port=item.http_port, ) + if item.adapter == 'websocket': + conf['adapter'] = test_instance(item.host, item.ws_port) + if item.adapter == 'kook': conf['adapter'] = KOOKBotInstance diff --git a/core/server/bot.py b/core/server/bot.py index 0ebed76e..2a90b0d2 100644 --- a/core/server/bot.py +++ b/core/server/bot.py @@ -4,9 +4,10 @@ from core.database.bot import BotAccounts, query_to_list from amiyabot.adapters.mirai import mirai_api_http from amiyabot.adapters.cqhttp import cq_http -from amiyabot.adapters.onebot11 import onebot11 -from amiyabot.adapters.onebot12 import onebot12 +from amiyabot.adapters.onebot.v11 import onebot11 +from amiyabot.adapters.onebot.v12 import onebot12 from amiyabot.adapters.comwechat import com_wechat +from amiyabot.adapters.test import test_instance from amiyabot.network.httpServer import BaseModel from amiyabot import AmiyaBot, KOOKBotInstance @@ -63,6 +64,10 @@ async def add_bot(self, data: BotAccountModel): if BotAccounts.get_or_none(appid=data.appid): return app.response(code=500, message='AppId 已存在') + if data.adapter == 'websocket': + if BotAccounts.get_or_none(adapter='websocket', ws_port=data.ws_port): + return app.response(code=500, message='websocket 适配器的 ws 端口不能重复') + BotAccounts.create(**data.get_data()) if data.start: @@ -72,6 +77,13 @@ async def add_bot(self, data: BotAccountModel): @app.route() async def edit_bot(self, data: BotAccountModel): + if BotAccounts.get_or_none(appid=data.appid): + return app.response(code=500, message='AppId 已存在') + + if data.adapter == 'websocket': + if BotAccounts.get_or_none(adapter='websocket', ws_port=data.ws_port): + return app.response(code=500, message='websocket 适配器的 ws 端口不能重复') + BotAccounts.update(**data.get_data()).where(BotAccounts.id == data.id).execute() if data.start: @@ -104,6 +116,9 @@ async def run_bot(self, data: BotAccountModel): http_port=data.http_port, ) + if data.adapter == 'websocket': + conf['adapter'] = test_instance(data.host, data.ws_port) + if data.adapter == 'kook': conf['adapter'] = KOOKBotInstance