Skip to content

Commit

Permalink
Merge pull request #264 from AmiyaBot/V6-dev
Browse files Browse the repository at this point in the history
V6 dev
  • Loading branch information
vivien8261 authored Jan 5, 2024
2 parents fdeccb2 + 6025dd5 commit d76ca75
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .github/publish.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v6.4.2
v6.4.3
74 changes: 46 additions & 28 deletions core/database/bot.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from amiyabot import AmiyaBot, KOOKBotInstance
from amiyabot.database import *
from amiyabot.adapters.mirai import mirai_api_http
from core.database import config, is_mysql
from typing import Union

from amiyabot.adapters.tencent.qqGroup import qq_group, QQGroupChainBuilderOptions
from amiyabot.adapters.cqhttp import cq_http
from amiyabot.adapters.mirai import mirai_api_http
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

db = connect_database('amiya_bot' if is_mysql else 'database/amiya_bot.db', is_mysql, config)

Expand Down Expand Up @@ -40,12 +42,24 @@ class BotAccounts(BotBaseModel):
host: str = CharField(null=True)
ws_port: int = IntegerField(null=True)
http_port: int = IntegerField(null=True)
client_secret: str = CharField(null=True)

@classmethod
def get_all_account(cls):
select: List[cls] = cls.select()
account = []

for item in select:
if not item.is_start:
continue

conf = cls.build_conf(item)
account.append(AmiyaBot(**conf))

return account

@classmethod
def build_conf(cls, item):
net_adapters = {
'mirai_api_http': mirai_api_http,
'cq_http': cq_http,
Expand All @@ -54,32 +68,36 @@ def get_all_account(cls):
'com_wechat': com_wechat,
}

for item in select:
if not item.is_start:
continue

conf = {
'appid': item.appid,
'token': item.token,
'private': bool(item.private),
}

if item.adapter in net_adapters:
conf['adapter'] = net_adapters[item.adapter](
host=item.host,
ws_port=item.ws_port,
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

account.append(AmiyaBot(**conf))
conf = {
'appid': item.appid,
'token': item.token,
'private': bool(item.private),
}

return account
if item.adapter in net_adapters:
conf['adapter'] = net_adapters[item.adapter](
host=item.host,
ws_port=item.ws_port,
http_port=item.http_port,
)

if item.adapter == 'qq_group':
conf['adapter'] = qq_group(
item.client_secret,
default_chain_builder_options=QQGroupChainBuilderOptions(
item.host or '0.0.0.0',
item.http_port or 8086,
'./resource/group_temp',
),
)

if item.adapter == 'websocket':
conf['adapter'] = test_instance(item.host, item.ws_port)

if item.adapter == 'kook':
conf['adapter'] = KOOKBotInstance

return conf


@table
Expand Down
37 changes: 4 additions & 33 deletions core/server/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@

from core import app, bot
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.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
from amiyabot import AmiyaBot


class BotAppId(BaseModel):
Expand All @@ -24,9 +18,11 @@ class BotAccountModel(BotAppId):
is_start: int = 1
adapter: str = 'tencent'
console_channel: Optional[str] = None

host: Optional[str] = None
ws_port: Optional[int] = None
http_port: Optional[int] = None
client_secret: Optional[str] = None

start: int = 0

Expand Down Expand Up @@ -96,32 +92,7 @@ async def run_bot(self, data: BotAccountModel):
if data.appid in bot:
return app.response(code=500, message='Bot 已存在')

net_adapters = {
'mirai_api_http': mirai_api_http,
'cq_http': cq_http,
'onebot11': onebot11,
'onebot12': onebot12,
'com_wechat': com_wechat,
}
conf = {
'appid': data.appid,
'token': data.token,
'private': bool(data.private),
}

if data.adapter in net_adapters:
conf['adapter'] = net_adapters[data.adapter](
host=data.host,
ws_port=data.ws_port,
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

conf = BotAccounts.build_conf(data)
bot.append(AmiyaBot(**conf), launch_browser=True)

return app.response(message=f'正在启动 AppId {data.appid}')
Expand Down
2 changes: 1 addition & 1 deletion pluginsDev
Submodule pluginsDev updated 39 files
+5 −0 .gitignore
+1 −1 src/arknights/calculator/main.py
+3 −0 src/arknights/calculator/money.py
+11 −3 src/arknights/gacha/gachaBuilder.py
+1 −0 src/arknights/operatorArchives/config_default.yaml
+6 −0 src/arknights/operatorArchives/config_schema.json
+2 −2 src/arknights/operatorArchives/operatorCore.py
+5 −1 src/arknights/recruit/README.md
+26 −2 src/arknights/recruit/main.py
+ src/arknights/recruit/tools/Windows.Media.Ocr.Cli.exe
+364 −0 src/blm/README.md
+0 −0 src/blm/__init__.py
+19 −0 src/blm/config_templates/global_config_default.json
+116 −0 src/blm/config_templates/global_config_schema.json
+ src/blm/images/chino_logo_comment.png
+ src/blm/logo.png
+54 −0 src/blm/main.py
+326 −0 src/blm/src/chat_gpt/chat_gpt_adapter.py
+177 −0 src/blm/src/common/blm_plugin_instance.py
+78 −0 src/blm/src/common/blm_types.py
+32 −0 src/blm/src/common/database.py
+74 −0 src/blm/src/common/extract_json.py
+360 −0 src/blm/src/ernie/ernie_adapter.py
+13 −0 src/chatBot/README.md
+0 −0 src/chatBot/README_USE.md
+1 −0 src/chatBot/__init__.py
+2 −2 src/chatBot/config_default.yaml
+36 −0 src/chatBot/config_schema.json
+ src/chatBot/logo.png
+161 −0 src/chatBot/main.py
+0 −0 src/chatBot/prompt/chat.txt
+0 −0 src/chatBot/template/Amiya.txt
+0 −15 src/ernieBot/README.md
+0 −68 src/ernieBot/config_schema.json
+ src/ernieBot/logo.png
+0 −203 src/ernieBot/main.py
+0 −5 src/ernieBot/models.py
+1 −1 src/func/main.py
+0 −1 src/func/template.md
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
amiyabot==1.8.4
amiyabot==1.8.6
attrdict~=2.0.1
baidu-aip
dhash~=1.3
Expand Down

0 comments on commit d76ca75

Please sign in to comment.