🐛 修复多余括号

This commit is contained in:
Wuyi无疑 2023-03-05 23:18:15 +08:00
parent f0ef919fb2
commit e0b638bc99

View File

@ -1,5 +1,5 @@
import asyncio import asyncio
from typing import List, Union, Optional from typing import Dict, List, Union, Optional
import websockets.client import websockets.client
from nonebot import get_bot from nonebot import get_bot
@ -8,7 +8,7 @@ from nonebot.adapters import Bot
from msgspec import json as msgjson from msgspec import json as msgjson
from websockets.exceptions import ConnectionClosedError from websockets.exceptions import ConnectionClosedError
from .models import Message, MessageSend, MessageReceive from .models import MessageSend, MessageReceive
BOT_ID = 'NoneBot2' BOT_ID = 'NoneBot2'
@ -109,7 +109,7 @@ async def onebot_send(
bot: Bot, bot: Bot,
content: Optional[str], content: Optional[str],
image: Optional[bytes], image: Optional[bytes],
node: Optional[List[Message]], node: Optional[List[Dict]],
target_id: Optional[str], target_id: Optional[str],
target_type: Optional[str], target_type: Optional[str],
): ):
@ -145,19 +145,17 @@ async def onebot_send(
) )
if node: if node:
messages = ( messages = [
[ to_json(
to_json( f'[CQ:image,file=base64://{_msg["data"]}]'
f'[CQ:image,file=base64://{_msg.data}]' if _msg['type'] == 'image'
if _msg.type == 'image' else _msg['data'],
else _msg.data, '小助手',
'小助手', 2854196310,
2854196310, )
) for _msg in node
for _msg in node if 'data' in _msg
if _msg.data ]
],
)
await _send_node(messages) await _send_node(messages)
else: else:
await _send(content, image) await _send(content, image)
@ -167,7 +165,7 @@ async def guild_send(
bot: Bot, bot: Bot,
content: Optional[str], content: Optional[str],
image: Optional[bytes], image: Optional[bytes],
node: Optional[List[Message]], node: Optional[List[Dict]],
target_id: Optional[str], target_id: Optional[str],
target_type: Optional[str], target_type: Optional[str],
): ):
@ -186,12 +184,12 @@ async def guild_send(
if node: if node:
for _msg in node: for _msg in node:
if _msg.type == 'image': if _msg['type'] == 'image':
image = _msg.data image = _msg['data']
content = None content = None
else: else:
image = None image = None
content = _msg.data content = _msg['data']
await _send(content, image) await _send(content, image)
else: else:
await _send(content, image) await _send(content, image)
@ -201,7 +199,7 @@ async def ntchat_send(
bot: Bot, bot: Bot,
content: Optional[str], content: Optional[str],
image: Optional[bytes], image: Optional[bytes],
node: Optional[List[Message]], node: Optional[List[Dict]],
target_id: Optional[str], target_id: Optional[str],
): ):
async def _send(content: Optional[str], image: Optional[bytes]): async def _send(content: Optional[str], image: Optional[bytes]):
@ -220,9 +218,9 @@ async def ntchat_send(
if node: if node:
for _msg in node: for _msg in node:
if _msg.type == 'image': if _msg['type'] == 'image':
await _send(None, _msg.data) await _send(None, _msg['data'])
else: else:
await _send(_msg.data, None) await _send(_msg['data'], None)
else: else:
await _send(content, image) await _send(content, image)