mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-05 11:26:43 +08:00
auto fix by pre-commit hooks
This commit is contained in:
parent
d3a782cb18
commit
cb0df0528e
@ -105,9 +105,9 @@ def do_add_sub(add_sub: Type[Matcher]):
|
||||
raise ValueError
|
||||
state["id"] = target
|
||||
state["name"] = name
|
||||
except(KeyboardInterrupt):
|
||||
except (KeyboardInterrupt):
|
||||
await add_sub.finish("已中止订阅")
|
||||
except(ValueError):
|
||||
except (ValueError):
|
||||
await add_sub.reject("id输入错误")
|
||||
|
||||
@add_sub.got("id", _gen_prompt_template("{_prompt}"), [Depends(parse_id)])
|
||||
@ -141,7 +141,7 @@ def do_add_sub(add_sub: Type[Matcher]):
|
||||
async def parser_tags(event: AbstractEvent, state: T_State):
|
||||
if not isinstance(state["tags"], Message):
|
||||
return
|
||||
if str(event.get_message()).strip() == "取消":#一般不会有叫 取消 的tag吧
|
||||
if str(event.get_message()).strip() == "取消": # 一般不会有叫 取消 的tag吧
|
||||
await add_sub.finish("已中止订阅")
|
||||
if str(event.get_message()).strip() == "全部标签":
|
||||
state["tags"] = []
|
||||
|
@ -12,8 +12,8 @@ class PlugConfig(BaseSettings):
|
||||
bison_filter_log: bool = False
|
||||
bison_to_me: bool = True
|
||||
bison_skip_browser_check: bool = False
|
||||
bison_use_pic_merge: int = 0#多图片时启用图片合并转发(仅限群),当bison_use_queue为False时该配置不会生效
|
||||
#0:不启用;1:首条消息单独发送,剩余照片合并转发;2以及以上:所有消息全部合并转发
|
||||
bison_use_pic_merge: int = 0 # 多图片时启用图片合并转发(仅限群),当bison_use_queue为False时该配置不会生效
|
||||
# 0:不启用;1:首条消息单独发送,剩余照片合并转发;2以及以上:所有消息全部合并转发
|
||||
class Config:
|
||||
extra = "ignore"
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
from email import message
|
||||
import time
|
||||
from email import message
|
||||
from typing import Literal, Union
|
||||
|
||||
from nonebot.adapters import Message, MessageSegment
|
||||
@ -8,26 +8,22 @@ from nonebot.log import logger
|
||||
|
||||
from .plugin_config import plugin_config
|
||||
|
||||
QUEUE = []#不开启图片合并转发时使用
|
||||
QUEUE = [] # 不开启图片合并转发时使用
|
||||
LAST_SEND_TIME = time.time()
|
||||
|
||||
def generate_forward_msg(
|
||||
msgs:list, self_id:str, nickname:str
|
||||
):
|
||||
group_msg=[]
|
||||
|
||||
def generate_forward_msg(msgs: list, self_id: str, nickname: str):
|
||||
group_msg = []
|
||||
for msg in msgs:
|
||||
sub_msg={
|
||||
"type":"node",
|
||||
"data": {
|
||||
"name": f"{nickname}",
|
||||
"uin": f"{self_id}",
|
||||
"content": f"{msg}"
|
||||
}
|
||||
sub_msg = {
|
||||
"type": "node",
|
||||
"data": {"name": f"{nickname}", "uin": f"{self_id}", "content": f"{msg}"},
|
||||
}
|
||||
group_msg.append(sub_msg)
|
||||
|
||||
|
||||
return group_msg
|
||||
|
||||
|
||||
async def _do_send(
|
||||
bot: "Bot", user: str, user_type: str, msg: Union[str, Message, MessageSegment]
|
||||
):
|
||||
@ -36,32 +32,37 @@ async def _do_send(
|
||||
elif user_type == "private":
|
||||
await bot.call_api("send_private_msg", user_id=user, message=msg)
|
||||
|
||||
|
||||
async def _do_merge_send(
|
||||
bot: Bot, user, user_type: Literal["private", "group"], msgs: list
|
||||
):
|
||||
):
|
||||
if plugin_config.bison_use_pic_merge == 1:
|
||||
try:
|
||||
await _do_send(bot, user, user_type, msgs.pop(0))#弹出第一条消息,剩下的消息合并
|
||||
except Exception as e_f:#first_msg_exception
|
||||
logger.error("向群{}发送消息序列首消息失败:{}".format(user,repr(e_f)))
|
||||
await _do_send(bot, user, user_type, msgs.pop(0)) # 弹出第一条消息,剩下的消息合并
|
||||
except Exception as e_f: # first_msg_exception
|
||||
logger.error("向群{}发送消息序列首消息失败:{}".format(user, repr(e_f)))
|
||||
else:
|
||||
logger.info("成功向群{}发送消息序列中的首条消息".format(user))
|
||||
try:
|
||||
if msgs:
|
||||
if len(msgs) == 1:#只有一条消息序列就不合并转发
|
||||
if len(msgs) == 1: # 只有一条消息序列就不合并转发
|
||||
await _do_send(bot, user, user_type, msgs.pop(0))
|
||||
else:
|
||||
group_bot_info = await bot.get_group_member_info(group_id=user,user_id=bot.self_id,no_cache=True)#调用api获取群内bot的相关参数
|
||||
forward_msg = generate_forward_msg(msgs = msgs,
|
||||
self_id = group_bot_info["user_id"],
|
||||
nickname = group_bot_info["card"]
|
||||
)#生成合并转发内容
|
||||
await bot.send_group_forward_msg(group_id=user,messages=forward_msg)
|
||||
except Exception as e_b:#behind_msg_exception
|
||||
logger.warning("向群{}发送合并图片消息超时或者可能失败:{}\n可能是因为图片太大或者太多".format(user,repr(e_b)))
|
||||
group_bot_info = await bot.get_group_member_info(
|
||||
group_id=user, user_id=bot.self_id, no_cache=True
|
||||
) # 调用api获取群内bot的相关参数
|
||||
forward_msg = generate_forward_msg(
|
||||
msgs=msgs,
|
||||
self_id=group_bot_info["user_id"],
|
||||
nickname=group_bot_info["card"],
|
||||
) # 生成合并转发内容
|
||||
await bot.send_group_forward_msg(group_id=user, messages=forward_msg)
|
||||
except Exception as e_b: # behind_msg_exception
|
||||
logger.warning("向群{}发送合并图片消息超时或者可能失败:{}\n可能是因为图片太大或者太多".format(user, repr(e_b)))
|
||||
else:
|
||||
logger.info("成功向群{}发送合并图片转发消息".format(user))
|
||||
|
||||
|
||||
async def do_send_msgs():
|
||||
global LAST_SEND_TIME
|
||||
if time.time() - LAST_SEND_TIME < 1.5:
|
||||
@ -81,7 +82,6 @@ async def do_send_msgs():
|
||||
LAST_SEND_TIME = time.time()
|
||||
|
||||
|
||||
|
||||
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_pic_merge and user_type == "group":
|
||||
|
Loading…
x
Reference in New Issue
Block a user