mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-05 11:26:43 +08:00
修复订阅列表为空时使用删除订阅命令无法跳出的问题
This commit is contained in:
parent
84e497e65a
commit
227cf0cfc1
@ -244,33 +244,38 @@ def do_del_sub(del_sub: Type[Matcher]):
|
|||||||
config: Config = Config()
|
config: Config = Config()
|
||||||
user_info = state["target_user_info"]
|
user_info = state["target_user_info"]
|
||||||
assert isinstance(user_info, User)
|
assert isinstance(user_info, User)
|
||||||
sub_list = config.list_subscribe(
|
try:
|
||||||
# state.get("_user_id") or event.group_id, "group"
|
sub_list = config.list_subscribe(
|
||||||
user_info.user,
|
# state.get("_user_id") or event.group_id, "group"
|
||||||
user_info.user_type,
|
user_info.user,
|
||||||
)
|
user_info.user_type,
|
||||||
res = "订阅的帐号为:\n"
|
|
||||||
state["sub_table"] = {}
|
|
||||||
for index, sub in enumerate(sub_list, 1):
|
|
||||||
state["sub_table"][index] = {
|
|
||||||
"target_type": sub["target_type"],
|
|
||||||
"target": sub["target"],
|
|
||||||
}
|
|
||||||
res += "{} {} {} {}\n".format(
|
|
||||||
index, sub["target_type"], sub["target_name"], sub["target"]
|
|
||||||
)
|
)
|
||||||
platform = platform_manager[sub["target_type"]]
|
assert sub_list
|
||||||
if platform.categories:
|
except AssertionError:
|
||||||
res += " [{}]".format(
|
await del_sub.finish("暂无已订阅账号\n请使用“添加订阅”命令添加订阅")
|
||||||
", ".join(
|
else:
|
||||||
map(lambda x: platform.categories[Category(x)], sub["cats"])
|
res = "订阅的帐号为:\n"
|
||||||
)
|
state["sub_table"] = {}
|
||||||
|
for index, sub in enumerate(sub_list, 1):
|
||||||
|
state["sub_table"][index] = {
|
||||||
|
"target_type": sub["target_type"],
|
||||||
|
"target": sub["target"],
|
||||||
|
}
|
||||||
|
res += "{} {} {} {}\n".format(
|
||||||
|
index, sub["target_type"], sub["target_name"], sub["target"]
|
||||||
)
|
)
|
||||||
if platform.enable_tag:
|
platform = platform_manager[sub["target_type"]]
|
||||||
res += " {}".format(", ".join(sub["tags"]))
|
if platform.categories:
|
||||||
res += "\n"
|
res += " [{}]".format(
|
||||||
res += "请输入要删除的订阅的序号\n输入'取消'中止"
|
", ".join(
|
||||||
await bot.send(event=event, message=Message(await parse_text(res)))
|
map(lambda x: platform.categories[Category(x)], sub["cats"])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
if platform.enable_tag:
|
||||||
|
res += " {}".format(", ".join(sub["tags"]))
|
||||||
|
res += "\n"
|
||||||
|
res += "请输入要删除的订阅的序号\n输入'取消'中止"
|
||||||
|
await bot.send(event=event, message=Message(await parse_text(res)))
|
||||||
|
|
||||||
@del_sub.receive()
|
@del_sub.receive()
|
||||||
async def do_del(event: Event, state: T_State):
|
async def do_del(event: Event, state: T_State):
|
||||||
|
@ -281,3 +281,49 @@ async def test_abort_add_on_tag(app: App):
|
|||||||
True,
|
True,
|
||||||
)
|
)
|
||||||
ctx.should_finished()
|
ctx.should_finished()
|
||||||
|
|
||||||
|
|
||||||
|
# 删除订阅阶段中止
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_abort_del_sub(app: App):
|
||||||
|
from nonebot.adapters.onebot.v11.bot import Bot
|
||||||
|
from nonebot.adapters.onebot.v11.message import Message
|
||||||
|
from nonebot_bison.config import Config
|
||||||
|
from nonebot_bison.config_manager import del_sub_matcher
|
||||||
|
from nonebot_bison.platform import platform_manager
|
||||||
|
|
||||||
|
config = Config()
|
||||||
|
config.user_target.truncate()
|
||||||
|
config.add_subscribe(
|
||||||
|
10000,
|
||||||
|
"group",
|
||||||
|
"6279793937",
|
||||||
|
"明日方舟Arknights",
|
||||||
|
"weibo",
|
||||||
|
[platform_manager["weibo"].reverse_category["图文"]],
|
||||||
|
["明日方舟"],
|
||||||
|
)
|
||||||
|
async with app.test_matcher(del_sub_matcher) as ctx:
|
||||||
|
bot = ctx.create_bot(base=Bot)
|
||||||
|
assert isinstance(bot, Bot)
|
||||||
|
event = fake_group_message_event(
|
||||||
|
message=Message("删除订阅"), to_me=True, sender=fake_admin_user
|
||||||
|
)
|
||||||
|
ctx.receive_event(bot, event)
|
||||||
|
ctx.should_pass_rule()
|
||||||
|
ctx.should_pass_permission()
|
||||||
|
ctx.should_call_send(
|
||||||
|
event,
|
||||||
|
Message(
|
||||||
|
"订阅的帐号为:\n1 weibo 明日方舟Arknights 6279793937\n [图文] 明日方舟\n请输入要删除的订阅的序号\n输入'取消'中止"
|
||||||
|
),
|
||||||
|
True,
|
||||||
|
)
|
||||||
|
event_abort = fake_group_message_event(
|
||||||
|
message=Message("取消"), sender=fake_admin_user
|
||||||
|
)
|
||||||
|
ctx.receive_event(bot, event_abort)
|
||||||
|
ctx.should_call_send(event_abort, "删除中止", True)
|
||||||
|
ctx.should_finished()
|
||||||
|
subs = config.list_subscribe(10000, "group")
|
||||||
|
assert subs
|
||||||
|
@ -85,3 +85,30 @@ async def test_del_sub(app: App):
|
|||||||
ctx.should_finished()
|
ctx.should_finished()
|
||||||
subs = config.list_subscribe(10000, "group")
|
subs = config.list_subscribe(10000, "group")
|
||||||
assert len(subs) == 0
|
assert len(subs) == 0
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_del_empty_sub(app: App):
|
||||||
|
from nonebot.adapters.onebot.v11.bot import Bot
|
||||||
|
from nonebot.adapters.onebot.v11.message import Message
|
||||||
|
from nonebot_bison.config import Config
|
||||||
|
from nonebot_bison.config_manager import del_sub_matcher
|
||||||
|
from nonebot_bison.platform import platform_manager
|
||||||
|
|
||||||
|
config = Config()
|
||||||
|
config.user_target.truncate()
|
||||||
|
async with app.test_matcher(del_sub_matcher) as ctx:
|
||||||
|
bot = ctx.create_bot(base=Bot)
|
||||||
|
assert isinstance(bot, Bot)
|
||||||
|
event = fake_group_message_event(
|
||||||
|
message=Message("删除订阅"), to_me=True, sender=fake_admin_user
|
||||||
|
)
|
||||||
|
ctx.receive_event(bot, event)
|
||||||
|
ctx.should_pass_rule()
|
||||||
|
ctx.should_pass_permission()
|
||||||
|
ctx.should_finished()
|
||||||
|
ctx.should_call_send(
|
||||||
|
event,
|
||||||
|
"暂无已订阅账号\n请使用“添加订阅”命令添加订阅",
|
||||||
|
True,
|
||||||
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user