mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-07-15 04:33:01 +08:00
添加了订阅过程中止功能
This commit is contained in:
parent
33533918ae
commit
65d0fd9ffc
src/plugins/nonebot_bison
@ -57,7 +57,7 @@ def do_add_sub(add_sub: Type[Matcher]):
|
||||
for platform_name in common_platform
|
||||
]
|
||||
)
|
||||
+ "要查看全部平台请输入:“全部”"
|
||||
+ "要查看全部平台请输入:“全部”\n中止订阅过程请输入:“取消”"
|
||||
)
|
||||
|
||||
async def parse_platform(event: AbstractEvent, state: T_State) -> None:
|
||||
@ -72,6 +72,8 @@ def do_add_sub(add_sub: Type[Matcher]):
|
||||
]
|
||||
)
|
||||
await add_sub.reject(message)
|
||||
elif platform == "取消":
|
||||
await add_sub.finish("已中止订阅")
|
||||
elif platform in platform_manager:
|
||||
state["platform"] = platform
|
||||
else:
|
||||
@ -96,12 +98,16 @@ def do_add_sub(add_sub: Type[Matcher]):
|
||||
return
|
||||
target = str(event.get_message()).strip()
|
||||
try:
|
||||
if target == "取消":
|
||||
raise KeyboardInterrupt
|
||||
name = await check_sub_target(state["platform"], target)
|
||||
if not name:
|
||||
raise ValueError
|
||||
state["id"] = target
|
||||
state["name"] = name
|
||||
except:
|
||||
except(KeyboardInterrupt):
|
||||
await add_sub.finish("已中止订阅")
|
||||
except(ValueError):
|
||||
await add_sub.reject("id输入错误")
|
||||
|
||||
@add_sub.got("id", _gen_prompt_template("{_prompt}"), [Depends(parse_id)])
|
||||
@ -118,7 +124,9 @@ def do_add_sub(add_sub: Type[Matcher]):
|
||||
return
|
||||
res = []
|
||||
for cat in str(event.get_message()).strip().split():
|
||||
if cat not in platform_manager[state["platform"]].reverse_category:
|
||||
if cat == "取消":
|
||||
await add_sub.finish("已中止订阅")
|
||||
elif cat not in platform_manager[state["platform"]].reverse_category:
|
||||
await add_sub.reject("不支持 {}".format(cat))
|
||||
res.append(platform_manager[state["platform"]].reverse_category[cat])
|
||||
state["cats"] = res
|
||||
@ -133,6 +141,8 @@ 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吧
|
||||
await add_sub.finish("已中止订阅")
|
||||
if str(event.get_message()).strip() == "全部标签":
|
||||
state["tags"] = []
|
||||
else:
|
||||
|
@ -12,6 +12,7 @@ class PlugConfig(BaseSettings):
|
||||
bison_filter_log: bool = False
|
||||
bison_to_me: bool = True
|
||||
bison_skip_browser_check: bool = False
|
||||
bison_use_pic_merge: bool = True#多图片时启用图片合并转发
|
||||
|
||||
class Config:
|
||||
extra = "ignore"
|
||||
|
48
src/plugins/nonebot_bison/send.py.bak
Normal file
48
src/plugins/nonebot_bison/send.py.bak
Normal file
@ -0,0 +1,48 @@
|
||||
import time
|
||||
from typing import Literal, Union
|
||||
|
||||
from nonebot.adapters import Message, MessageSegment
|
||||
from nonebot.adapters.onebot.v11.bot import Bot
|
||||
from nonebot.log import logger
|
||||
|
||||
from .plugin_config import plugin_config
|
||||
|
||||
QUEUE = []
|
||||
LAST_SEND_TIME = time.time()
|
||||
|
||||
|
||||
async def _do_send(
|
||||
bot: "Bot", user: str, user_type: str, msg: Union[str, Message, MessageSegment]
|
||||
):
|
||||
if user_type == "group":
|
||||
await bot.call_api("send_group_msg", group_id=user, message=msg)
|
||||
elif user_type == "private":
|
||||
await bot.call_api("send_private_msg", user_id=user, message=msg)
|
||||
|
||||
|
||||
async def do_send_msgs():
|
||||
global LAST_SEND_TIME
|
||||
if time.time() - LAST_SEND_TIME < 1.5:
|
||||
return
|
||||
if QUEUE:
|
||||
bot, user, user_type, msg, retry_time = QUEUE.pop(0)
|
||||
try:
|
||||
await _do_send(bot, user, user_type, msg)
|
||||
except Exception as e:
|
||||
if retry_time > 0:
|
||||
QUEUE.insert(0, (bot, user, user_type, msg, retry_time - 1))
|
||||
else:
|
||||
msg_str = str(msg)
|
||||
if len(msg_str) > 50:
|
||||
msg_str = msg_str[:50] + "..."
|
||||
logger.warning(f"send msg err {e} {msg_str}")
|
||||
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:
|
||||
for msg in msgs:
|
||||
QUEUE.append((bot, user, user_type, msg, 2))
|
||||
else:
|
||||
for msg in msgs:
|
||||
await _do_send(bot, user, user_type, msg)
|
Loading…
x
Reference in New Issue
Block a user