mirror of
https://github.com/KimigaiiWuyi/GenshinUID.git
synced 2025-05-12 06:55:58 +08:00
🎨 优化多连接适配
This commit is contained in:
parent
e1f057a09a
commit
d8ac046014
14
.vscode/settings.json
vendored
14
.vscode/settings.json
vendored
@ -11,9 +11,21 @@
|
|||||||
"nonebug",
|
"nonebug",
|
||||||
"weapontype"
|
"weapontype"
|
||||||
],
|
],
|
||||||
|
"editor.formatOnSave": true,
|
||||||
"[python]": {
|
"[python]": {
|
||||||
|
"editor.defaultFormatter": "ms-python.black-formatter",
|
||||||
|
"editor.formatOnSave": true,
|
||||||
"editor.codeActionsOnSave": {
|
"editor.codeActionsOnSave": {
|
||||||
"source.organizeImports": true
|
"source.organizeImports": true
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"isort.args": [
|
||||||
|
"--profile",
|
||||||
|
"black"
|
||||||
|
],
|
||||||
|
"python.formatting.provider": "black",
|
||||||
|
"python.linting.flake8Enabled": true,
|
||||||
|
"python.linting.flake8CategorySeverity.W": "Warning",
|
||||||
|
"python.linting.flake8CategorySeverity.F": "Warning",
|
||||||
|
"python.linting.flake8CategorySeverity.E": "Warning",
|
||||||
}
|
}
|
@ -5,10 +5,10 @@ from pathlib import Path
|
|||||||
from typing import Any, Dict, List, Union, Optional
|
from typing import Any, Dict, List, Union, Optional
|
||||||
|
|
||||||
import websockets.client
|
import websockets.client
|
||||||
from nonebot import get_bots
|
|
||||||
from nonebot.log import logger
|
from nonebot.log import logger
|
||||||
from nonebot.adapters import Bot
|
from nonebot.adapters import Bot
|
||||||
from msgspec import json as msgjson
|
from msgspec import json as msgjson
|
||||||
|
from nonebot import get_bot, get_bots
|
||||||
from websockets.exceptions import ConnectionClosedError
|
from websockets.exceptions import ConnectionClosedError
|
||||||
|
|
||||||
from .models import MessageSend, MessageReceive
|
from .models import MessageSend, MessageReceive
|
||||||
@ -17,6 +17,19 @@ BOT_ID = 'NoneBot2'
|
|||||||
bots: Dict[str, str] = {}
|
bots: Dict[str, str] = {}
|
||||||
|
|
||||||
|
|
||||||
|
def _get_bot(bot_id: str) -> Bot:
|
||||||
|
if 'onebot' in bot_id:
|
||||||
|
bot_id = 'onebot'
|
||||||
|
if bot_id not in bots:
|
||||||
|
for _bot_id in bots.keys():
|
||||||
|
if bot_id in _bot_id:
|
||||||
|
bot_id = _bot_id
|
||||||
|
break
|
||||||
|
bot_real_id = bots[bot_id]
|
||||||
|
bot = get_bot(bot_real_id)
|
||||||
|
return bot
|
||||||
|
|
||||||
|
|
||||||
class GsClient:
|
class GsClient:
|
||||||
@classmethod
|
@classmethod
|
||||||
async def async_connect(
|
async def async_connect(
|
||||||
@ -48,8 +61,11 @@ class GsClient:
|
|||||||
f'【接收】[gsuid-core]: '
|
f'【接收】[gsuid-core]: '
|
||||||
f'{msg.bot_id} - {msg.target_type} - {msg.target_id}'
|
f'{msg.bot_id} - {msg.target_type} - {msg.target_id}'
|
||||||
)
|
)
|
||||||
|
bot_list = []
|
||||||
if msg.bot_self_id in _bots:
|
if msg.bot_self_id in _bots:
|
||||||
bot = _bots[msg.bot_self_id]
|
bot_list.append(_bots[msg.bot_self_id])
|
||||||
|
elif not msg.bot_self_id:
|
||||||
|
bot_list.append(_get_bot(msg.bot_id))
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@ -80,6 +96,7 @@ class GsClient:
|
|||||||
|
|
||||||
# 根据bot_id字段发送消息
|
# 根据bot_id字段发送消息
|
||||||
# OneBot v11 & v12
|
# OneBot v11 & v12
|
||||||
|
for bot in bot_list:
|
||||||
if msg.bot_id == 'onebot':
|
if msg.bot_id == 'onebot':
|
||||||
await onebot_send(
|
await onebot_send(
|
||||||
bot,
|
bot,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user