♻️ 改进代码 (#591)

* refactor: 改进代码

* 🚨 `pre-commit-ci`修复格式错误

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
qianxu 2023-10-13 01:30:42 +08:00 committed by GitHub
parent 44bd8b63b6
commit 5d793c65c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -405,11 +405,12 @@ async def onebot_red_send(
target_type: Optional[str],
):
from nonebot.adapters.red.bot import Bot
from nonebot.adapters.red.api.model import ChatType
from nonebot.adapters.red.message import Message, MessageSegment
assert isinstance(bot, Bot)
chat_type = 2 if target_type == 'group' else 1
chat_type = ChatType.GROUP if target_type == 'group' else ChatType.FRIEND
async def _send(content: Optional[str], image: Optional[str]):
result_msg: Message = Message()
@ -431,11 +432,7 @@ async def onebot_red_send(
result_msg += MessageSegment.file(path)
if target_id:
await bot.send_message(
chat_type, # type: ignore
target_id,
result_msg,
)
await bot.send_message(chat_type, target_id, result_msg)
if file:
del_file(path) # type: ignore