From 6410b5c3ca1d2b20b16dd35d8a346b64e98ead53 Mon Sep 17 00:00:00 2001 From: Azide Date: Tue, 12 Apr 2022 00:16:15 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=A2=9E=E6=B7=BB=E5=85=B3=E4=BA=8E?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=AE=A2=E9=98=85=E5=91=BD=E4=BB=A4=E4=B8=AD?= =?UTF-8?q?=E4=B8=AD=E6=AD=A2=E8=AE=A2=E9=98=85=E7=9A=84=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/usage/README.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/docs/usage/README.md b/docs/usage/README.md index 5c51a1e..4caefa8 100644 --- a/docs/usage/README.md +++ b/docs/usage/README.md @@ -152,25 +152,33 @@ sidebar: auto 所有命令都需要@bot 触发 - 添加订阅(仅管理员和群主和 SUPERUSER):`添加订阅` + ::: tip 关于中止订阅 + 对于[**v0.5.1**](https://github.com/felinae98/nonebot-bison/releases/tag/v0.5.1)及以上的版本中,已经为`添加订阅`命令添加了中止订阅的功能。 + 在添加订阅命令的~~几乎~~各个阶段,都可以向 Bot 发送`取消`消息来中止订阅过程(需要订阅发起者本人发送) + ::: - 查询订阅:`查询订阅` - 删除订阅(仅管理员和群主和 SUPERUSER):`删除订阅` #### 私聊机器人获取后台地址 `后台管理`,之后点击返回的链接 -如果你是 superuser,那么你可以管理所有群的订阅;如果你是 bot 所在的群的其中部分群的管理, -你可以管理你管理的群里的订阅;如果你不是任意一个群的管理,那么 bot 将会报错。 +如果你是 superuser,那么你可以管理所有群的订阅; +如果你是 bot 所在的群的其中部分群的管理,你可以管理你管理的群里的订阅; +如果你不是任意一个群的管理,那么 bot 将会报错。 ::: tip 可以和 bot 通过临时聊天触发 ::: ::: warning -网页的身份鉴别机制全部由 bot 返回的链接确定,所以这个链接并不能透露给别人。 +网页的身份鉴别机制全部由 bot 返回的链接确定,所以这个链接并不能透露给别人。 并且链接会过期,所以一段时间后需要重新私聊 bot 获取新的链接。 ::: #### 私聊机器人进行配置(需要 SUPERUER 权限) 请私聊 bot`群管理` +::: tip 关于中止订阅 +与普通的[`添加订阅`](#在本群中进行配置)命令一样,在`群管理`命令中使用的`添加订阅`命令也可以使用`取消`来中止订阅过程 +::: ### 所支持平台的 uid From d0f56e76cd47a967a155dca9e48be1fe1fb8908f Mon Sep 17 00:00:00 2001 From: felinae98 <731499577@qq.com> Date: Sat, 30 Apr 2022 00:48:06 +0800 Subject: [PATCH 2/4] release v0.5.2 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 3bfb5d6..38dafe9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "nonebot-bison" -version = "0.5.1" +version = "0.5.2" description = "Subscribe message from social medias" authors = ["felinae98 "] license = "MIT" From 84e497e65a8437aa216bbbbdee656e0df7c4c6ed Mon Sep 17 00:00:00 2001 From: Azide Date: Wed, 11 May 2022 17:36:16 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E8=AE=A2=E9=98=85=E5=91=BD=E4=BB=A4=E7=9A=84=E5=8F=96=E6=B6=88?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/nonebot_bison/config_manager.py | 7 +++++-- tests/test_config_manager_add.py | 4 ++-- tests/test_config_manager_query_del.py | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/plugins/nonebot_bison/config_manager.py b/src/plugins/nonebot_bison/config_manager.py index 931bf3e..21438ee 100644 --- a/src/plugins/nonebot_bison/config_manager.py +++ b/src/plugins/nonebot_bison/config_manager.py @@ -269,13 +269,16 @@ def do_del_sub(del_sub: Type[Matcher]): if platform.enable_tag: res += " {}".format(", ".join(sub["tags"])) res += "\n" - res += "请输入要删除的订阅的序号" + res += "请输入要删除的订阅的序号\n输入'取消'中止" await bot.send(event=event, message=Message(await parse_text(res))) @del_sub.receive() async def do_del(event: Event, state: T_State): + user_msg = str(event.get_message()).strip() + if user_msg == "取消": + await del_sub.finish("删除中止") try: - index = int(str(event.get_message()).strip()) + index = int(user_msg) config = Config() user_info = state["target_user_info"] assert isinstance(user_info, User) diff --git a/tests/test_config_manager_add.py b/tests/test_config_manager_add.py index a38a1a8..ae679c0 100644 --- a/tests/test_config_manager_add.py +++ b/tests/test_config_manager_add.py @@ -387,8 +387,8 @@ async def test_add_with_get_id(app: App): True, ) """ - line 362: - 鬼知道为什么要在这里这样写, + 关于Message([MessageSegment(*BotReply.add_reply_on_id_input_search())]): + 异客知道为什么要在这里这样写, 没有[]的话assert不了(should_call_send使用[MessageSegment(...)]的格式进行比较) 不在这里MessageSegment()的话也assert不了(指不能让add_reply_on_id_input_search直接返回一个MessageSegment对象) amen diff --git a/tests/test_config_manager_query_del.py b/tests/test_config_manager_query_del.py index 51dd80d..4cad12f 100644 --- a/tests/test_config_manager_query_del.py +++ b/tests/test_config_manager_query_del.py @@ -67,7 +67,7 @@ async def test_del_sub(app: App): ctx.should_call_send( event, Message( - "订阅的帐号为:\n1 weibo 明日方舟Arknights 6279793937\n [图文] 明日方舟\n请输入要删除的订阅的序号" + "订阅的帐号为:\n1 weibo 明日方舟Arknights 6279793937\n [图文] 明日方舟\n请输入要删除的订阅的序号\n输入'取消'中止" ), True, ) From 227cf0cfc1c5fe373a75604736f72271d2a0e967 Mon Sep 17 00:00:00 2001 From: Azide Date: Wed, 11 May 2022 18:27:47 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=AE=A2=E9=98=85?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E4=B8=BA=E7=A9=BA=E6=97=B6=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E8=AE=A2=E9=98=85=E5=91=BD=E4=BB=A4=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E8=B7=B3=E5=87=BA=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/nonebot_bison/config_manager.py | 55 +++++++++++---------- tests/test_config_manager_abort.py | 46 +++++++++++++++++ tests/test_config_manager_query_del.py | 27 ++++++++++ 3 files changed, 103 insertions(+), 25 deletions(-) diff --git a/src/plugins/nonebot_bison/config_manager.py b/src/plugins/nonebot_bison/config_manager.py index 21438ee..c284adb 100644 --- a/src/plugins/nonebot_bison/config_manager.py +++ b/src/plugins/nonebot_bison/config_manager.py @@ -244,33 +244,38 @@ def do_del_sub(del_sub: Type[Matcher]): config: Config = Config() user_info = state["target_user_info"] assert isinstance(user_info, User) - sub_list = config.list_subscribe( - # state.get("_user_id") or event.group_id, "group" - 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"] + try: + sub_list = config.list_subscribe( + # state.get("_user_id") or event.group_id, "group" + user_info.user, + user_info.user_type, ) - platform = platform_manager[sub["target_type"]] - if platform.categories: - res += " [{}]".format( - ", ".join( - map(lambda x: platform.categories[Category(x)], sub["cats"]) - ) + assert sub_list + except AssertionError: + await del_sub.finish("暂无已订阅账号\n请使用“添加订阅”命令添加订阅") + else: + 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: - res += " {}".format(", ".join(sub["tags"])) - res += "\n" - res += "请输入要删除的订阅的序号\n输入'取消'中止" - await bot.send(event=event, message=Message(await parse_text(res))) + platform = platform_manager[sub["target_type"]] + if platform.categories: + res += " [{}]".format( + ", ".join( + 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() async def do_del(event: Event, state: T_State): diff --git a/tests/test_config_manager_abort.py b/tests/test_config_manager_abort.py index da307f4..65921a1 100644 --- a/tests/test_config_manager_abort.py +++ b/tests/test_config_manager_abort.py @@ -281,3 +281,49 @@ async def test_abort_add_on_tag(app: App): True, ) 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 diff --git a/tests/test_config_manager_query_del.py b/tests/test_config_manager_query_del.py index 4cad12f..f995a9c 100644 --- a/tests/test_config_manager_query_del.py +++ b/tests/test_config_manager_query_del.py @@ -85,3 +85,30 @@ async def test_del_sub(app: App): ctx.should_finished() subs = config.list_subscribe(10000, "group") 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, + )