From 5b9e255586075726aef3cfdb85af4270d2f10e20 Mon Sep 17 00:00:00 2001 From: Azide Date: Mon, 21 Feb 2022 21:01:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E5=A2=9E=E5=8A=A0=E5=90=88?= =?UTF-8?q?=E5=B9=B6=E6=B6=88=E6=81=AF=E8=BD=AC=E5=8F=91=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=20=E5=BE=85=E9=AA=8C=E8=AF=81=E6=98=AF=E5=90=A6=E5=8F=AF?= =?UTF-8?q?=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/nonebot_bison/plugin_config.py | 4 +++- src/plugins/nonebot_bison/send.py | 24 ++++++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/plugins/nonebot_bison/plugin_config.py b/src/plugins/nonebot_bison/plugin_config.py index 8c9b5b5..b43a3d8 100644 --- a/src/plugins/nonebot_bison/plugin_config.py +++ b/src/plugins/nonebot_bison/plugin_config.py @@ -9,10 +9,12 @@ class PlugConfig(BaseSettings): bison_config_path: str = "" bison_use_pic: bool = False bison_use_local: bool = False + bison_use_forward_pic = True#当图片超过1张时改为合并消息发送 + #bison_browser: str = "local:C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" bison_browser: str = "" bison_init_filter: bool = True bison_use_queue: bool = True - bison_outer_url: str = "http://localhost:8080/bison/" + bison_outer_url: str = "http://localhost:15556/bison/" bison_filter_log: bool = False bison_to_me: bool = True diff --git a/src/plugins/nonebot_bison/send.py b/src/plugins/nonebot_bison/send.py index 1518636..031b684 100644 --- a/src/plugins/nonebot_bison/send.py +++ b/src/plugins/nonebot_bison/send.py @@ -1,5 +1,6 @@ +from email import message import time -from typing import Literal, Union +from typing import List, Literal, Union from nonebot.adapters import Message, MessageSegment from nonebot.adapters.onebot.v11.bot import Bot @@ -19,6 +20,22 @@ async def _do_send( elif user_type == "private": await bot.call_api("send_private_msg", user_id=user, message=msg) +async def _do_send_forward( + bot: "Bot", user: str, msgs: list +): + group_msg = [] + bot_info = await bot.call_api("get_login_info")#猜测返回list 第一个为user_id,第二个为nickname + for msg in msgs: + sub_msg = { + "type": "node", + "data": { + "name": f"{bot_info[0]}", + "uin": f"{bot_info[1]}", + "content": msg + } + } + group_msg.append(sub_msg) + await bot.call_api("send_group_forward_msg", group_id=user, message=group_msg) async def do_send_msgs(): global LAST_SEND_TIME @@ -40,7 +57,10 @@ async def do_send_msgs(): async def send_msgs(bot: Bot, user, user_type: Literal["private", "group"], msgs: list): - if plugin_config.bison_use_queue: + if plugin_config.bison_use_forward_pic and user_type!="private": + if msgs: + _do_send_forward(bot, user, msgs) + elif plugin_config.bison_use_queue: for msg in msgs: QUEUE.append((bot, user, user_type, msg, 2)) else: