Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
vivien8261 committed Nov 14, 2023
1 parent 0a644ee commit 6bcb126
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
8 changes: 6 additions & 2 deletions core/database/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
19 changes: 17 additions & 2 deletions core/server/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 6bcb126

Please sign in to comment.