From 00576f4b70886baab6335f33a0ecd1c4892d479e Mon Sep 17 00:00:00 2001 From: Azide Date: Thu, 17 Mar 2022 00:23:51 +0800 Subject: [PATCH 01/17] update changelog.md --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 953fae6..8f68581 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -66,5 +66,8 @@ ## [0.5.1] -- 使用了新的私聊进行群管理的方式 +- 使用了新的在私聊中进行群管理的方式:从`管理-*`替换为`群管理`命令 - 默认关闭自动重发功能 +- 添加了 [推送消息合并转发功能](https://nonebot-bison.vercel.app/usage/#%E9%85%8D%E7%BD%AE) +- 添加了`添加订阅`命令事件的中途取消功能 +- 优化了`添加订阅`命令的聊天处理逻辑 From 9c3dc7059ed1d239dcdc39a14faa402e2dcd6487 Mon Sep 17 00:00:00 2001 From: felinae98 <731499577@qq.com> Date: Sun, 20 Mar 2022 11:13:44 +0800 Subject: [PATCH 02/17] add target parser && add parser for bilibili --- src/plugins/nonebot_bison/config_manager.py | 12 +- .../nonebot_bison/platform/bilibili.py | 12 +- .../nonebot_bison/platform/platform.py | 7 ++ .../static/bilibili_arknights_profile.json | 1 + tests/test_config_manager_add.py | 109 ++++++++++++++++++ tests/utils.py | 1 + 6 files changed, 139 insertions(+), 3 deletions(-) create mode 100644 tests/platforms/static/bilibili_arknights_profile.json diff --git a/src/plugins/nonebot_bison/config_manager.py b/src/plugins/nonebot_bison/config_manager.py index 931bf3e..b939b88 100644 --- a/src/plugins/nonebot_bison/config_manager.py +++ b/src/plugins/nonebot_bison/config_manager.py @@ -15,6 +15,7 @@ from nonebot.params import Depends, EventPlainText, EventToMe from nonebot.permission import SUPERUSER from nonebot.rule import to_me from nonebot.typing import T_State +from nonebot_bison.platform.platform import Platform from .config import Config from .platform import check_sub_target, platform_manager @@ -108,8 +109,11 @@ def do_add_sub(add_sub: Type[Matcher]): "platform", _gen_prompt_template("{_prompt}"), [Depends(parse_platform)] ) async def init_id(state: T_State): - if platform_manager[state["platform"]].has_target: - state["_prompt"] = "请输入订阅用户的id:\n查询id获取方法请回复:“查询”" + cur_platform = platform_manager[state["platform"]] + if cur_platform.has_target: + state["_prompt"] = ( + cur_platform.parse_target_promot or "请输入订阅用户的id:\n查询id获取方法请回复:“查询”" + ) else: state["id"] = "default" state["name"] = await platform_manager[state["platform"]].get_target_name( @@ -125,6 +129,8 @@ def do_add_sub(add_sub: Type[Matcher]): raise LookupError if target == "取消": raise KeyboardInterrupt + platform = platform_manager[state["platform"]] + target = await platform.parse_target(target) name = await check_sub_target(state["platform"], target) if not name: raise ValueError @@ -141,6 +147,8 @@ def do_add_sub(add_sub: Type[Matcher]): await add_sub.finish("已中止订阅") except (ValueError): await add_sub.reject("id输入错误") + except (Platform.ParseTargetException): + await add_sub.reject("不能从你的输入中提取出id,请检查你输入的内容是否符合预期") else: await add_sub.send( "即将订阅的用户为:{} {} {}\n如有错误请输入“取消”重新订阅".format( diff --git a/src/plugins/nonebot_bison/platform/bilibili.py b/src/plugins/nonebot_bison/platform/bilibili.py index 5ff3cc1..94327ec 100644 --- a/src/plugins/nonebot_bison/platform/bilibili.py +++ b/src/plugins/nonebot_bison/platform/bilibili.py @@ -1,11 +1,12 @@ import json +import re from typing import Any, Optional import httpx from ..post import Post from ..types import Category, RawPost, Tag, Target -from .platform import CategoryNotSupport, NewMessage +from .platform import CategoryNotSupport, NewMessage, Platform class Bilibili(NewMessage): @@ -26,6 +27,7 @@ class Bilibili(NewMessage): schedule_kw = {"seconds": 10} name = "B站" has_target = True + parse_target_promot = "请输入用户主页的链接" async def get_target_name(self, target: Target) -> Optional[str]: async with httpx.AsyncClient() as client: @@ -37,6 +39,14 @@ class Bilibili(NewMessage): return None return res_data["data"]["name"] + async def parse_target(self, target_text: str) -> Target: + if re.match(r"\d+", target_text): + return Target(target_text) + elif match := re.match(r"(?:https://)?space.bilibili.com/(\d+)", target_text): + return Target(match.group(1)) + else: + raise Platform.ParseTargetException() + async def get_sub_list(self, target: Target) -> list[RawPost]: async with httpx.AsyncClient() as client: params = {"host_uid": target, "offset": 0, "need_top": 0} diff --git a/src/plugins/nonebot_bison/platform/platform.py b/src/plugins/nonebot_bison/platform/platform.py index e1c3471..19f002d 100644 --- a/src/plugins/nonebot_bison/platform/platform.py +++ b/src/plugins/nonebot_bison/platform/platform.py @@ -47,6 +47,7 @@ class Platform(metaclass=RegistryABCMeta, base=True): enable_tag: bool store: dict[Target, Any] platform_name: str + parse_target_promot: Optional[str] = None @abstractmethod async def get_target_name(self, target: Target) -> Optional[str]: @@ -73,6 +74,12 @@ class Platform(metaclass=RegistryABCMeta, base=True): self.reverse_category[val] = key self.store = dict() + class ParseTargetException(Exception): + pass + + async def parse_target(self, target_string: str) -> Target: + return Target(target_string) + @abstractmethod def get_tags(self, raw_post: RawPost) -> Optional[Collection[Tag]]: "Return Tag list of given RawPost" diff --git a/tests/platforms/static/bilibili_arknights_profile.json b/tests/platforms/static/bilibili_arknights_profile.json new file mode 100644 index 0000000..6e46b23 --- /dev/null +++ b/tests/platforms/static/bilibili_arknights_profile.json @@ -0,0 +1 @@ +{"code":0,"message":"0","ttl":1,"data":{"mid":161775300,"name":"明日方舟","sex":"保密","face":"http://i0.hdslb.com/bfs/face/89154378c06a5ed332c40c2ca56f50cd641c0c90.jpg","face_nft":0,"sign":"重铸未来 方舟启航","rank":10000,"level":6,"jointime":0,"moral":0,"silence":0,"coins":0,"fans_badge":true,"fans_medal":{"show":false,"wear":false,"medal":null},"official":{"role":3,"title":"明日方舟官方账号","desc":"","type":1},"vip":{"type":2,"status":1,"due_date":1648828800000,"vip_pay_type":0,"theme_type":0,"label":{"path":"","text":"年度大会员","label_theme":"annual_vip","text_color":"#FFFFFF","bg_style":1,"bg_color":"#FB7299","border_color":""},"avatar_subscript":1,"nickname_color":"#FB7299","role":3,"avatar_subscript_url":"http://i0.hdslb.com/bfs/vip/icon_Certification_big_member_22_3x.png"},"pendant":{"pid":5305,"name":"明日方舟音律系列","image":"http://i0.hdslb.com/bfs/garb/item/615a1653281141ddf64cbb98c792ddaee78f7f40.png","expire":0,"image_enhance":"http://i0.hdslb.com/bfs/garb/item/516ecdf2d495a62f1bac31497c831b711823140c.webp","image_enhance_frame":"http://i0.hdslb.com/bfs/garb/item/c0751afbf950373c260254d02768eabf30ff3906.png"},"nameplate":{"nid":0,"name":"","image":"","image_small":"","level":"","condition":""},"user_honour_info":{"mid":0,"colour":null,"tags":[]},"is_followed":true,"top_photo":"http://i1.hdslb.com/bfs/space/6c6084808ec5bdff1985acc05ce0e126c49ad76e.png","theme":{},"sys_notice":{},"live_room":{"roomStatus":1,"liveStatus":0,"url":"https://live.bilibili.com/5555734?broadcast_type=0\u0026is_room_feed=1","title":"《明日方舟》2022新春前瞻特辑","cover":"http://i0.hdslb.com/bfs/live/new_room_cover/79af83a27f6001c1acfb47d1c0b879290f7c3308.jpg","roomid":5555734,"roundStatus":1,"broadcast_type":0,"watched_show":{"switch":true,"num":13033,"text_small":"1.3万","text_large":"1.3万人看过","icon":"https://i0.hdslb.com/bfs/live/a725a9e61242ef44d764ac911691a7ce07f36c1d.png","icon_location":"","icon_web":"https://i0.hdslb.com/bfs/live/8d9d0f33ef8bf6f308742752d13dd0df731df19c.png"}},"birthday":"","school":null,"profession":{"name":"","department":"","title":"","is_show":0},"tags":null,"series":{"user_upgrade_status":3,"show_upgrade_window":false},"is_senior_member":0}} diff --git a/tests/test_config_manager_add.py b/tests/test_config_manager_add.py index a38a1a8..1f7552b 100644 --- a/tests/test_config_manager_add.py +++ b/tests/test_config_manager_add.py @@ -405,3 +405,112 @@ async def test_add_with_get_id(app: App): ctx.should_finished() subs = config.list_subscribe(10000, "group") assert len(subs) == 0 + + +@pytest.mark.asyncio +@respx.mock +async def test_add_with_target_parser(app: App): + from nonebot.adapters.onebot.v11.event import Sender + from nonebot.adapters.onebot.v11.message import Message + from nonebot_bison.config import Config + from nonebot_bison.config_manager import add_sub_matcher, common_platform + from nonebot_bison.platform import platform_manager + from nonebot_bison.platform.bilibili import Bilibili + + config = Config() + config.user_target.truncate() + + ak_list_router = respx.get( + "https://api.bilibili.com/x/space/acc/info?mid=161775300" + ) + ak_list_router.mock( + return_value=Response(200, json=get_json("bilibili_arknights_profile.json")) + ) + + async with app.test_matcher(add_sub_matcher) as ctx: + bot = ctx.create_bot() + event_1 = fake_group_message_event( + message=Message("添加订阅"), + sender=Sender(card="", nickname="test", role="admin"), + to_me=True, + ) + ctx.receive_event(bot, event_1) + ctx.should_pass_rule() + ctx.should_call_send( + event_1, + Message( + BotReply.add_reply_on_platform( + platform_manager=platform_manager, common_platform=common_platform + ) + ), + True, + ) + event_2 = fake_group_message_event( + message=Message("全部"), sender=Sender(card="", nickname="test", role="admin") + ) + ctx.receive_event(bot, event_2) + ctx.should_rejected() + ctx.should_call_send( + event_2, + BotReply.add_reply_on_platform_input_allplatform(platform_manager), + True, + ) + event_3 = fake_group_message_event( + message=Message("bilibili"), sender=fake_admin_user + ) + ctx.receive_event(bot, event_3) + assert Bilibili.parse_target_promot + ctx.should_call_send( + event_3, + Message(Bilibili.parse_target_promot), + True, + ) + event_4_err = fake_group_message_event( + message=Message( + "htps://space.bilbili.com/161775300?from=search&seid=13051774060625135297&spm_id_from=333.337.0.0" + ), + sender=fake_admin_user, + ) + ctx.receive_event(bot, event_4_err) + ctx.should_call_send( + event_4_err, BotReply.add_reply_on_target_parse_input_error, True + ) + ctx.should_rejected() + event_4_ok = fake_group_message_event( + message=Message( + "https://space.bilibili.com/161775300?from=search&seid=13051774060625135297&spm_id_from=333.337.0.0" + ), + sender=fake_admin_user, + ) + ctx.receive_event(bot, event_4_ok) + ctx.should_call_send( + event_4_ok, + BotReply.add_reply_on_target_confirm("bilibili", "明日方舟", "161775300"), + True, + ) + ctx.should_call_send( + event_4_ok, + Message(BotReply.add_reply_on_cats(platform_manager, "bilibili")), + True, + ) + event_5_ok = fake_group_message_event( + message=Message("视频"), sender=fake_admin_user + ) + ctx.receive_event(bot, event_5_ok) + ctx.should_call_send(event_5_ok, Message(BotReply.add_reply_on_tags), True) + event_6 = fake_group_message_event( + message=Message("全部标签"), sender=fake_admin_user + ) + ctx.receive_event(bot, event_6) + ctx.should_call_send( + event_6, BotReply.add_reply_subscribe_success("明日方舟"), True + ) + ctx.should_finished() + subs = config.list_subscribe(10000, "group") + assert len(subs) == 1 + sub = subs[0] + assert sub["target"] == "161775300" + assert sub["tags"] == [] + assert sub["cats"] == [platform_manager["bilibili"].reverse_category["视频"]] + assert sub["target_type"] == "bilibili" + assert sub["target_name"] == "明日方舟" diff --git a/tests/utils.py b/tests/utils.py index bd1930d..821544a 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -131,6 +131,7 @@ class BotReply: return "添加 {} 成功".format(name) add_reply_on_id_input_error = "id输入错误" + add_reply_on_target_parse_input_error = "不能从你的输入中提取出id,请检查你输入的内容是否符合预期" add_reply_on_platform_input_error = "平台输入错误" add_reply_on_id = "请输入订阅用户的id:\n查询id获取方法请回复:“查询”" add_reply_on_tags = '请输入要订阅的tag,订阅所有tag输入"全部标签"' From ee153a58ee46d7e17fe63f4de37935b5093e073c Mon Sep 17 00:00:00 2001 From: felinae98 <731499577@qq.com> Date: Sun, 20 Mar 2022 11:20:23 +0800 Subject: [PATCH 03/17] update ci file --- .circleci/main.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.circleci/main.yml b/.circleci/main.yml index 0e5e293..0d9d5ab 100644 --- a/.circleci/main.yml +++ b/.circleci/main.yml @@ -90,13 +90,13 @@ workflows: filters: tags: ignore: /.*/ - tag: ${CIRCLE_BRANCH} + tag: ${CIRCLE_BRANCH//\//-} cache_from: '$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME:${CIRCLE_BRANCH}' - docker/publish: <<: *docker-push dockerfile: docker/Dockerfile_with_frontend_sentry name: "docker/publish-sentry" - tag: sentry,${CIRCLE_TAG}-sentry + tag: sentry,${CIRCLE_TAG//\//-}-sentry cache_from: '$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME:sentry' - docker/publish: <<: *docker-push @@ -107,7 +107,7 @@ workflows: only: [main, dev] tags: ignore: /.*/ - tag: ${CIRCLE_BRANCH}-sentry + tag: ${CIRCLE_BRANCH//\//-}-sentry cache_from: '$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME:${CIRCLE_BRANCH}-sentry' jobs: From 539e75b0b328a5d2067e4f4d4f6ec1ef62c81035 Mon Sep 17 00:00:00 2001 From: Azide Date: Sun, 20 Mar 2022 18:46:00 +0800 Subject: [PATCH 04/17] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E9=A1=B9=E6=8F=8F=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/nonebot_bison/plugin_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/nonebot_bison/plugin_config.py b/src/plugins/nonebot_bison/plugin_config.py index 10ded5f..c6b5c71 100644 --- a/src/plugins/nonebot_bison/plugin_config.py +++ b/src/plugins/nonebot_bison/plugin_config.py @@ -12,7 +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: int = 0 # 多图片时启用图片合并转发(仅限群),当bison_use_queue为False时该配置不会生效 + bison_use_pic_merge: int = 0 # 多图片时启用图片合并转发(仅限群) # 0:不启用;1:首条消息单独发送,剩余照片合并转发;2以及以上:所有消息全部合并转发 bison_resend_times: int = 0 From ba508c180eb09f44d60d0cfd609f3449190efa2b Mon Sep 17 00:00:00 2001 From: Azide Date: Sun, 20 Mar 2022 20:23:25 +0800 Subject: [PATCH 05/17] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=B7=BB=E5=8A=A0id?= =?UTF-8?q?=E5=89=8D=E7=9A=84=E5=9B=9E=E5=A4=8D=E8=AF=AD=E5=8F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/nonebot_bison/config_manager.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/plugins/nonebot_bison/config_manager.py b/src/plugins/nonebot_bison/config_manager.py index b939b88..f4b3193 100644 --- a/src/plugins/nonebot_bison/config_manager.py +++ b/src/plugins/nonebot_bison/config_manager.py @@ -112,8 +112,10 @@ def do_add_sub(add_sub: Type[Matcher]): cur_platform = platform_manager[state["platform"]] if cur_platform.has_target: state["_prompt"] = ( - cur_platform.parse_target_promot or "请输入订阅用户的id:\n查询id获取方法请回复:“查询”" - ) + ("1." + cur_platform.parse_target_promot + "\n2.") + if cur_platform.parse_target_promot + else "" + ) + "请输入订阅用户的id\n查询id获取方法请回复:“查询”" else: state["id"] = "default" state["name"] = await platform_manager[state["platform"]].get_target_name( From 063c3ea883553f26e72244a247577d131cfb182f Mon Sep 17 00:00:00 2001 From: Azide Date: Sun, 20 Mar 2022 20:27:53 +0800 Subject: [PATCH 06/17] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_config_manager_add.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_config_manager_add.py b/tests/test_config_manager_add.py index 1f7552b..197e159 100644 --- a/tests/test_config_manager_add.py +++ b/tests/test_config_manager_add.py @@ -387,7 +387,7 @@ 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对象) From 6c09772980556fd14244e93d500f60866708b81d Mon Sep 17 00:00:00 2001 From: Azide Date: Sun, 20 Mar 2022 20:32:36 +0800 Subject: [PATCH 07/17] =?UTF-8?q?=E4=BF=AE=E6=94=B9test=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_config_manager_add.py | 4 +++- tests/utils.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_config_manager_add.py b/tests/test_config_manager_add.py index 197e159..32f8b8c 100644 --- a/tests/test_config_manager_add.py +++ b/tests/test_config_manager_add.py @@ -462,7 +462,9 @@ async def test_add_with_target_parser(app: App): assert Bilibili.parse_target_promot ctx.should_call_send( event_3, - Message(Bilibili.parse_target_promot), + Message( + "1." + Bilibili.parse_target_promot + "\n2." + BotReply.add_reply_on_id + ), True, ) event_4_err = fake_group_message_event( diff --git a/tests/utils.py b/tests/utils.py index 821544a..6de13c2 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -133,6 +133,6 @@ class BotReply: add_reply_on_id_input_error = "id输入错误" add_reply_on_target_parse_input_error = "不能从你的输入中提取出id,请检查你输入的内容是否符合预期" add_reply_on_platform_input_error = "平台输入错误" - add_reply_on_id = "请输入订阅用户的id:\n查询id获取方法请回复:“查询”" + add_reply_on_id = "请输入订阅用户的id\n查询id获取方法请回复:“查询”" add_reply_on_tags = '请输入要订阅的tag,订阅所有tag输入"全部标签"' add_reply_abort = "已中止订阅" From 1763662ed01227623a643c8a3b2c85bb153c01fa Mon Sep 17 00:00:00 2001 From: Azide Date: Sun, 20 Mar 2022 23:22:54 +0800 Subject: [PATCH 08/17] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=AD=A3=E5=88=99?= =?UTF-8?q?=EF=BC=8C=E5=B0=9D=E8=AF=95=E6=8C=89=E7=85=A7bilibil=E7=9A=84pa?= =?UTF-8?q?rse=5Ftarget=E6=B7=BB=E5=8A=A0weibo=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/nonebot_bison/platform/bilibili.py | 2 +- src/plugins/nonebot_bison/platform/weibo.py | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/plugins/nonebot_bison/platform/bilibili.py b/src/plugins/nonebot_bison/platform/bilibili.py index 94327ec..b6c83c9 100644 --- a/src/plugins/nonebot_bison/platform/bilibili.py +++ b/src/plugins/nonebot_bison/platform/bilibili.py @@ -42,7 +42,7 @@ class Bilibili(NewMessage): async def parse_target(self, target_text: str) -> Target: if re.match(r"\d+", target_text): return Target(target_text) - elif match := re.match(r"(?:https://)?space.bilibili.com/(\d+)", target_text): + elif match := re.match(r"(?:https?://)?space.bilibili.com/(\d+)", target_text): return Target(match.group(1)) else: raise Platform.ParseTargetException() diff --git a/src/plugins/nonebot_bison/platform/weibo.py b/src/plugins/nonebot_bison/platform/weibo.py index 2e9f46b..7d5ef57 100644 --- a/src/plugins/nonebot_bison/platform/weibo.py +++ b/src/plugins/nonebot_bison/platform/weibo.py @@ -9,7 +9,7 @@ from nonebot.log import logger from ..post import Post from ..types import * -from .platform import NewMessage +from .platform import NewMessage, Platform class Weibo(NewMessage): @@ -28,6 +28,7 @@ class Weibo(NewMessage): schedule_type = "interval" schedule_kw = {"seconds": 3} has_target = True + parse_target_promot = "请输入用户主页(包含数字UID)的链接" async def get_target_name(self, target: Target) -> Optional[str]: async with httpx.AsyncClient() as client: @@ -41,6 +42,15 @@ class Weibo(NewMessage): else: return None + async def parse_target(self, target_text: str) -> Target: + if re.match(r"\d+", target_text): + return Target(target_text) + elif match := re.match(r"(?:https?://)?weibo.com/u/(\d+)", target_text): + # 都2202年了应该不会有http了吧,不过还是防一手 + return Target(match.group(1)) + else: + raise Platform.ParseTargetException() + async def get_sub_list(self, target: Target) -> list[RawPost]: async with httpx.AsyncClient() as client: params = {"containerid": "107603" + target} From e390b1292cff12b0dd6db0e2603d065f998fbc24 Mon Sep 17 00:00:00 2001 From: Azide Date: Mon, 21 Mar 2022 00:31:04 +0800 Subject: [PATCH 09/17] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=8E=9F=E6=9C=89?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E4=BD=BF=E4=B9=8B=E7=AC=A6=E5=90=88=E6=96=B0?= =?UTF-8?q?=E7=9A=84=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_config_manager_abort.py | 9 ++++++--- tests/test_config_manager_add.py | 13 +++++++------ tests/utils.py | 12 +++++++++++- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/tests/test_config_manager_abort.py b/tests/test_config_manager_abort.py index da307f4..a7d694c 100644 --- a/tests/test_config_manager_abort.py +++ b/tests/test_config_manager_abort.py @@ -67,6 +67,7 @@ async def test_abort_add_on_id(app: App): from nonebot_bison.config import Config from nonebot_bison.config_manager import add_sub_matcher, common_platform from nonebot_bison.platform import platform_manager + from nonebot_bison.platform.weibo import Weibo config = Config() config.user_target.truncate() @@ -103,7 +104,7 @@ async def test_abort_add_on_id(app: App): ctx.receive_event(bot, event_2) ctx.should_call_send( event_2, - Message(BotReply.add_reply_on_id), + Message(BotReply.add_reply_on_id(Weibo)), True, ) event_abort = fake_group_message_event( @@ -127,6 +128,7 @@ async def test_abort_add_on_cats(app: App): from nonebot_bison.config import Config from nonebot_bison.config_manager import add_sub_matcher, common_platform from nonebot_bison.platform import platform_manager + from nonebot_bison.platform.weibo import Weibo config = Config() config.user_target.truncate() @@ -167,7 +169,7 @@ async def test_abort_add_on_cats(app: App): ctx.receive_event(bot, event_2) ctx.should_call_send( event_2, - Message(BotReply.add_reply_on_id), + Message(BotReply.add_reply_on_id(Weibo)), True, ) event_3 = fake_group_message_event( @@ -207,6 +209,7 @@ async def test_abort_add_on_tag(app: App): from nonebot_bison.config import Config from nonebot_bison.config_manager import add_sub_matcher, common_platform from nonebot_bison.platform import platform_manager + from nonebot_bison.platform.weibo import Weibo config = Config() config.user_target.truncate() @@ -247,7 +250,7 @@ async def test_abort_add_on_tag(app: App): ctx.receive_event(bot, event_2) ctx.should_call_send( event_2, - Message(BotReply.add_reply_on_id), + Message(BotReply.add_reply_on_id(Weibo)), True, ) event_3 = fake_group_message_event( diff --git a/tests/test_config_manager_add.py b/tests/test_config_manager_add.py index 32f8b8c..cbb1764 100644 --- a/tests/test_config_manager_add.py +++ b/tests/test_config_manager_add.py @@ -64,6 +64,7 @@ async def test_add_with_target(app: App): from nonebot_bison.config import Config from nonebot_bison.config_manager import add_sub_matcher, common_platform from nonebot_bison.platform import platform_manager + from nonebot_bison.platform.weibo import Weibo config = Config() config.user_target.truncate() @@ -115,7 +116,7 @@ async def test_add_with_target(app: App): ctx.receive_event(bot, event_3) ctx.should_call_send( event_3, - Message(BotReply.add_reply_on_id), + Message(BotReply.add_reply_on_id(Weibo)), True, ) event_4_err = fake_group_message_event( @@ -181,6 +182,7 @@ async def test_add_with_target_no_cat(app: App): from nonebot_bison.config import Config from nonebot_bison.config_manager import add_sub_matcher, common_platform from nonebot_bison.platform import platform_manager + from nonebot_bison.platform.ncm_artist import NcmArtist config = Config() config.user_target.truncate() @@ -208,7 +210,7 @@ async def test_add_with_target_no_cat(app: App): ctx.receive_event(bot, event_3) ctx.should_call_send( event_3, - Message(BotReply.add_reply_on_id), + Message(BotReply.add_reply_on_id(NcmArtist)), True, ) event_4_ok = fake_group_message_event( @@ -332,6 +334,7 @@ async def test_add_with_get_id(app: App): from nonebot_bison.config import Config from nonebot_bison.config_manager import add_sub_matcher, common_platform from nonebot_bison.platform import platform_manager + from nonebot_bison.platform.weibo import Weibo config = Config() config.user_target.truncate() @@ -373,7 +376,7 @@ async def test_add_with_get_id(app: App): ctx.receive_event(bot, event_3) ctx.should_call_send( event_3, - Message(BotReply.add_reply_on_id), + Message(BotReply.add_reply_on_id(Weibo)), True, ) event_4_query = fake_group_message_event( @@ -462,9 +465,7 @@ async def test_add_with_target_parser(app: App): assert Bilibili.parse_target_promot ctx.should_call_send( event_3, - Message( - "1." + Bilibili.parse_target_promot + "\n2." + BotReply.add_reply_on_id - ), + Message(BotReply.add_reply_on_id(Bilibili)), True, ) event_4_err = fake_group_message_event( diff --git a/tests/utils.py b/tests/utils.py index 6de13c2..08bdbe2 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -1,3 +1,4 @@ +from ast import Str from typing import TYPE_CHECKING from typing_extensions import Literal @@ -130,9 +131,18 @@ class BotReply: def add_reply_subscribe_success(name): return "添加 {} 成功".format(name) + @staticmethod + def add_reply_on_id(platform: object) -> Str: + base_text = "请输入订阅用户的id\n查询id获取方法请回复:“查询”" + extra_text = ( + ("1." + platform.parse_target_promot + "\n2.") + if platform.parse_target_promot + else "" + ) + return extra_text + base_text + add_reply_on_id_input_error = "id输入错误" add_reply_on_target_parse_input_error = "不能从你的输入中提取出id,请检查你输入的内容是否符合预期" add_reply_on_platform_input_error = "平台输入错误" - add_reply_on_id = "请输入订阅用户的id\n查询id获取方法请回复:“查询”" add_reply_on_tags = '请输入要订阅的tag,订阅所有tag输入"全部标签"' add_reply_abort = "已中止订阅" From 54b5070b207b4e879d316e6a868a1e44d7af8e5d Mon Sep 17 00:00:00 2001 From: Azide Date: Mon, 21 Mar 2022 00:51:19 +0800 Subject: [PATCH 10/17] =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E5=8E=9F=E6=9C=89=E6=B5=8B=E8=AF=95=EF=BC=8C=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?weibo=E8=BE=93=E5=85=A5=E9=93=BE=E6=8E=A5=E8=AE=A2=E9=98=85?= =?UTF-8?q?=E7=9A=84=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_config_manager_add.py | 125 +++++++++++++++++++++++++++++-- 1 file changed, 120 insertions(+), 5 deletions(-) diff --git a/tests/test_config_manager_add.py b/tests/test_config_manager_add.py index cbb1764..e341929 100644 --- a/tests/test_config_manager_add.py +++ b/tests/test_config_manager_add.py @@ -412,7 +412,7 @@ async def test_add_with_get_id(app: App): @pytest.mark.asyncio @respx.mock -async def test_add_with_target_parser(app: App): +async def test_add_with_bilibili_target_parser(app: App): from nonebot.adapters.onebot.v11.event import Sender from nonebot.adapters.onebot.v11.message import Message from nonebot_bison.config import Config @@ -468,17 +468,30 @@ async def test_add_with_target_parser(app: App): Message(BotReply.add_reply_on_id(Bilibili)), True, ) - event_4_err = fake_group_message_event( + event_4_err1 = fake_group_message_event( message=Message( - "htps://space.bilbili.com/161775300?from=search&seid=13051774060625135297&spm_id_from=333.337.0.0" + "https://live.bilibili.com/5555734?broadcast_type=0&is_room_feed=1&spm_id_from=333.999.0.0" ), sender=fake_admin_user, ) - ctx.receive_event(bot, event_4_err) + ctx.receive_event(bot, event_4_err1) ctx.should_call_send( - event_4_err, BotReply.add_reply_on_target_parse_input_error, True + event_4_err1, BotReply.add_reply_on_target_parse_input_error, True ) ctx.should_rejected() + + event_4_err1 = fake_group_message_event( + message=Message( + "https://space.bilibili.com/ark161775300?from=search&seid=13051774060625135297&spm_id_from=333.337.0.0" + ), + sender=fake_admin_user, + ) + ctx.receive_event(bot, event_4_err1) + ctx.should_call_send( + event_4_err1, BotReply.add_reply_on_target_parse_input_error, True + ) + ctx.should_rejected() + event_4_ok = fake_group_message_event( message=Message( "https://space.bilibili.com/161775300?from=search&seid=13051774060625135297&spm_id_from=333.337.0.0" @@ -517,3 +530,105 @@ async def test_add_with_target_parser(app: App): assert sub["cats"] == [platform_manager["bilibili"].reverse_category["视频"]] assert sub["target_type"] == "bilibili" assert sub["target_name"] == "明日方舟" + + +@pytest.mark.asyncio +@respx.mock +async def test_add_with_weibo_target_parser(app: App): + from nonebot.adapters.onebot.v11.event import Sender + from nonebot.adapters.onebot.v11.message import Message + from nonebot_bison.config import Config + from nonebot_bison.config_manager import add_sub_matcher, common_platform + from nonebot_bison.platform import platform_manager + from nonebot_bison.platform.weibo import Weibo + + config = Config() + config.user_target.truncate() + + ak_list_router = respx.get( + "https://m.weibo.cn/api/container/getIndex?containerid=1005056279793937" + ) + ak_list_router.mock( + return_value=Response(200, json=get_json("weibo_ak_profile.json")) + ) + ak_list_bad_router = respx.get( + "https://m.weibo.cn/api/container/getIndex?containerid=100505000" + ) + ak_list_bad_router.mock( + return_value=Response(200, json=get_json("weibo_err_profile.json")) + ) + async with app.test_matcher(add_sub_matcher) as ctx: + bot = ctx.create_bot() + event_1 = fake_group_message_event( + message=Message("添加订阅"), + sender=Sender(card="", nickname="test", role="admin"), + to_me=True, + ) + ctx.receive_event(bot, event_1) + ctx.should_pass_rule() + ctx.should_call_send( + event_1, + Message( + BotReply.add_reply_on_platform( + platform_manager=platform_manager, common_platform=common_platform + ) + ), + True, + ) + event_2 = fake_group_message_event( + message=Message("weibo"), sender=fake_admin_user + ) + ctx.receive_event(bot, event_2) + ctx.should_call_send( + event_2, + Message(BotReply.add_reply_on_id(Weibo)), + True, + ) + event_3_err1 = fake_group_message_event( + message=Message( + "https://space.bilbili.com/161775300?from=search&seid=13051774060625135297&spm_id_from=333.337.0.0" + ), + sender=fake_admin_user, + ) + ctx.receive_event(bot, event_3_err1) + ctx.should_call_send( + event_3_err1, BotReply.add_reply_on_target_parse_input_error, True + ) + ctx.should_rejected() + + event_3_err2 = fake_group_message_event( + message=Message("https://weibo.com/arknights"), + sender=fake_admin_user, + ) + ctx.receive_event(bot, event_3_err2) + ctx.should_call_send( + event_3_err2, BotReply.add_reply_on_target_parse_input_error, True + ) + ctx.should_rejected() + + event_3_err3 = fake_group_message_event( + message=Message("https://weibo.com/u/ark6279793937"), + sender=fake_admin_user, + ) + ctx.receive_event(bot, event_3_err3) + ctx.should_call_send( + event_3_err3, BotReply.add_reply_on_target_parse_input_error, True + ) + ctx.should_rejected() + + event_3_ok = fake_group_message_event( + message=Message("http://weibo.com/u/6279793937"), sender=fake_admin_user + ) # 特意写成http测试正则 + ctx.receive_event(bot, event_3_ok) + ctx.should_call_send( + event_3_ok, + BotReply.add_reply_on_target_confirm( + "weibo", "明日方舟Arknights", "6279793937" + ), + True, + ) + ctx.should_call_send( + event_3_ok, + Message(BotReply.add_reply_on_cats(platform_manager, "weibo")), + True, + ) From 831b2f2ca1110f0e6e9598a791a6ac2c0172e333 Mon Sep 17 00:00:00 2001 From: felinae98 <731499577@qq.com> Date: Mon, 21 Mar 2022 15:46:48 +0800 Subject: [PATCH 11/17] update ncm_artist ncm_radio --- .../nonebot_bison/platform/bilibili.py | 4 +- .../nonebot_bison/platform/ncm_artist.py | 12 +++ .../nonebot_bison/platform/ncm_radio.py | 12 +++ src/plugins/nonebot_bison/platform/weibo.py | 8 +- tests/platforms/test_bilibili.py | 23 ++++ tests/platforms/test_ncm_artist.py | 17 +++ tests/platforms/test_ncm_radio.py | 15 +++ tests/platforms/test_weibo.py | 17 +++ tests/test_config_manager_add.py | 102 ------------------ 9 files changed, 103 insertions(+), 107 deletions(-) diff --git a/src/plugins/nonebot_bison/platform/bilibili.py b/src/plugins/nonebot_bison/platform/bilibili.py index b6c83c9..9d62045 100644 --- a/src/plugins/nonebot_bison/platform/bilibili.py +++ b/src/plugins/nonebot_bison/platform/bilibili.py @@ -42,7 +42,9 @@ class Bilibili(NewMessage): async def parse_target(self, target_text: str) -> Target: if re.match(r"\d+", target_text): return Target(target_text) - elif match := re.match(r"(?:https?://)?space.bilibili.com/(\d+)", target_text): + elif match := re.match( + r"(?:https?://)?space\.bilibili\.com/(\d+)", target_text + ): return Target(match.group(1)) else: raise Platform.ParseTargetException() diff --git a/src/plugins/nonebot_bison/platform/ncm_artist.py b/src/plugins/nonebot_bison/platform/ncm_artist.py index a30072f..9895dde 100644 --- a/src/plugins/nonebot_bison/platform/ncm_artist.py +++ b/src/plugins/nonebot_bison/platform/ncm_artist.py @@ -1,3 +1,4 @@ +import re from typing import Any, Optional import httpx @@ -18,6 +19,7 @@ class NcmArtist(NewMessage): schedule_kw = {"minutes": 1} name = "网易云-歌手" has_target = True + parse_target_promot = "请输入歌手主页(包含数字ID)的链接" async def get_target_name(self, target: Target) -> Optional[str]: async with httpx.AsyncClient() as client: @@ -30,6 +32,16 @@ class NcmArtist(NewMessage): return return res_data["artist"]["name"] + async def parse_target(self, target_text: str) -> Target: + if re.match(r"^\d+$", target_text): + return Target(target_text) + elif match := re.match( + r"(?:https?://)?music\.163\.com/#/artist\?id=(\d+)", target_text + ): + return Target(match.group(1)) + else: + raise self.ParseTargetException() + async def get_sub_list(self, target: Target) -> list[RawPost]: async with httpx.AsyncClient() as client: res = await client.get( diff --git a/src/plugins/nonebot_bison/platform/ncm_radio.py b/src/plugins/nonebot_bison/platform/ncm_radio.py index 20abb52..973cc1b 100644 --- a/src/plugins/nonebot_bison/platform/ncm_radio.py +++ b/src/plugins/nonebot_bison/platform/ncm_radio.py @@ -1,3 +1,4 @@ +import re from typing import Any, Optional import httpx @@ -18,6 +19,7 @@ class NcmRadio(NewMessage): schedule_kw = {"minutes": 10} name = "网易云-电台" has_target = True + parse_target_promot = "请输入主播电台主页(包含数字ID)的链接" async def get_target_name(self, target: Target) -> Optional[str]: async with httpx.AsyncClient() as client: @@ -31,6 +33,16 @@ class NcmRadio(NewMessage): return return res_data["programs"][0]["radio"]["name"] + async def parse_target(self, target_text: str) -> Target: + if re.match(r"^\d+$", target_text): + return Target(target_text) + elif match := re.match( + r"(?:https?://)?music\.163\.com/#/djradio\?id=(\d+)", target_text + ): + return Target(match.group(1)) + else: + raise self.ParseTargetException() + async def get_sub_list(self, target: Target) -> list[RawPost]: async with httpx.AsyncClient() as client: res = await client.post( diff --git a/src/plugins/nonebot_bison/platform/weibo.py b/src/plugins/nonebot_bison/platform/weibo.py index 7d5ef57..b2b211d 100644 --- a/src/plugins/nonebot_bison/platform/weibo.py +++ b/src/plugins/nonebot_bison/platform/weibo.py @@ -45,7 +45,7 @@ class Weibo(NewMessage): async def parse_target(self, target_text: str) -> Target: if re.match(r"\d+", target_text): return Target(target_text) - elif match := re.match(r"(?:https?://)?weibo.com/u/(\d+)", target_text): + elif match := re.match(r"(?:https?://)?weibo\.com/u/(\d+)", target_text): # 都2202年了应该不会有http了吧,不过还是防一手 return Target(match.group(1)) else: @@ -139,9 +139,9 @@ class Weibo(NewMessage): "https://m.weibo.cn/detail/{}".format(info["mid"]), headers=header ) try: - full_json_text = re.search( - r'"status": ([\s\S]+),\s+"hotScheme"', res.text - ).group(1) + match = re.search(r'"status": ([\s\S]+),\s+"hotScheme"', res.text) + assert match + full_json_text = match.group(1) info = json.loads(full_json_text) except: logger.info( diff --git a/tests/platforms/test_bilibili.py b/tests/platforms/test_bilibili.py index 5fc2b28..afcd426 100644 --- a/tests/platforms/test_bilibili.py +++ b/tests/platforms/test_bilibili.py @@ -1,3 +1,5 @@ +import typing + import pytest from httpx import Response from nonebug.app import App @@ -10,6 +12,10 @@ def bing_dy_list(): return get_json("bilibili_bing_list.json")["data"]["cards"] +if typing.TYPE_CHECKING: + from nonebot_bison.platform.bilibili import Bilibili + + @pytest.fixture def bilibili(app: App): from nonebot_bison.platform import platform_manager @@ -46,3 +52,20 @@ async def test_dynamic_forward(bilibili, bing_dy_list): + "\n--------------\n" + "#明日方舟#\n【新增服饰】\n//殿堂上的游禽 - 星极\n塞壬唱片偶像企划《闪耀阶梯》特供服饰/殿堂上的游禽。星极自费参加了这项企划,尝试着用大众能接受的方式演绎天空之上的故事。\n\n_____________\n谦逊留给观众,骄傲发自歌喉,此夜,唯我璀璨。 " ) + + +async def test_parse_target(bilibili: "Bilibili"): + from nonebot_bison.platform.platform import Platform + + res = await bilibili.parse_target( + "https://space.bilibili.com/161775300?from=search&seid=130517740606234234234&spm_id_from=333.337.0.0" + ) + assert res == "161775300" + res2 = await bilibili.parse_target( + "space.bilibili.com/161775300?from=search&seid=130517740606234234234&spm_id_from=333.337.0.0" + ) + assert res2 == "161775300" + with pytest.raises(Platform.ParseTargetException): + await bilibili.parse_target( + "https://www.bilibili.com/video/BV1qP4y1g738?spm_id_from=333.999.0.0" + ) diff --git a/tests/platforms/test_ncm_artist.py b/tests/platforms/test_ncm_artist.py index 354b2a6..8f8f4cd 100644 --- a/tests/platforms/test_ncm_artist.py +++ b/tests/platforms/test_ncm_artist.py @@ -1,4 +1,5 @@ import time +import typing import pytest import respx @@ -7,6 +8,9 @@ from nonebug.app import App from .utils import get_json +if typing.TYPE_CHECKING: + from nonebot_bison.platform.ncm_artist import NcmArtist + @pytest.fixture def ncm_artist(app: App): @@ -48,3 +52,16 @@ async def test_fetch_new(ncm_artist, ncm_artist_0, ncm_artist_1, dummy_user_subi assert post.target_type == "ncm-artist" assert post.text == "新专辑发布:Y1K" assert post.url == "https://music.163.com/#/album?id=131074504" + + +async def test_parse_target(ncm_artist: "NcmArtist"): + from nonebot_bison.platform.platform import Platform + + res = await ncm_artist.parse_target("32540734") + assert res == "32540734" + res = await ncm_artist.parse_target("https://music.163.com/#/artist?id=32540734") + assert res == "32540734" + res = await ncm_artist.parse_target("music.163.com/#/artist?id=32540734") + assert res == "32540734" + with pytest.raises(Platform.ParseTargetException): + await ncm_artist.parse_target("music.163.com/#/rad?id=32540734") diff --git a/tests/platforms/test_ncm_radio.py b/tests/platforms/test_ncm_radio.py index d191c6f..9bab7d8 100644 --- a/tests/platforms/test_ncm_radio.py +++ b/tests/platforms/test_ncm_radio.py @@ -1,4 +1,5 @@ import time +import typing import pytest import respx @@ -7,6 +8,9 @@ from nonebug.app import App from .utils import get_json +if typing.TYPE_CHECKING: + from nonebot_bison.platform.ncm_radio import NcmRadio + @pytest.fixture def ncm_radio(app: App): @@ -53,3 +57,14 @@ async def test_fetch_new(ncm_radio, ncm_radio_0, ncm_radio_1, dummy_user_subinfo "http://p1.music.126.net/H5em5xUNIYXcjJhOmeaSqQ==/109951166647436789.jpg" ] assert post.target_name == "《明日方舟》游戏原声OST" + + +async def test_parse_target(ncm_radio: "NcmRadio"): + res = await ncm_radio.parse_target("https://music.163.com/#/djradio?id=793745436") + assert res == "793745436" + res = await ncm_radio.parse_target("music.163.com/#/djradio?id=793745436") + assert res == "793745436" + res = await ncm_radio.parse_target("793745436") + assert res == "793745436" + with pytest.raises(ncm_radio.ParseTargetException): + await ncm_radio.parse_target("music.163.com/#/alm?id=793745436") diff --git a/tests/platforms/test_weibo.py b/tests/platforms/test_weibo.py index c241408..742d9a3 100644 --- a/tests/platforms/test_weibo.py +++ b/tests/platforms/test_weibo.py @@ -1,3 +1,4 @@ +import typing from datetime import datetime import feedparser @@ -9,6 +10,9 @@ from pytz import timezone from .utils import get_file, get_json +if typing.TYPE_CHECKING: + from nonebot_bison.platform.weibo import Weibo + @pytest.fixture def weibo(app: App): @@ -125,3 +129,16 @@ def test_chaohua_tag(weibo): tags = weibo.get_tags(test_post) assert "刚出生的小羊驼长啥样" in tags assert "小羊驼三三超话" in tags + + +async def test_parse_target(weibo: "Weibo"): + from nonebot_bison.platform.platform import Platform + + res = await weibo.parse_target("https://weibo.com/u/6441489862") + assert res == "6441489862" + res = await weibo.parse_target("weibo.com/u/6441489862") + assert res == "6441489862" + res = await weibo.parse_target("6441489862") + assert res == "6441489862" + with pytest.raises(Platform.ParseTargetException): + await weibo.parse_target("https://weibo.com/arknights") diff --git a/tests/test_config_manager_add.py b/tests/test_config_manager_add.py index e341929..8064f0d 100644 --- a/tests/test_config_manager_add.py +++ b/tests/test_config_manager_add.py @@ -530,105 +530,3 @@ async def test_add_with_bilibili_target_parser(app: App): assert sub["cats"] == [platform_manager["bilibili"].reverse_category["视频"]] assert sub["target_type"] == "bilibili" assert sub["target_name"] == "明日方舟" - - -@pytest.mark.asyncio -@respx.mock -async def test_add_with_weibo_target_parser(app: App): - from nonebot.adapters.onebot.v11.event import Sender - from nonebot.adapters.onebot.v11.message import Message - from nonebot_bison.config import Config - from nonebot_bison.config_manager import add_sub_matcher, common_platform - from nonebot_bison.platform import platform_manager - from nonebot_bison.platform.weibo import Weibo - - config = Config() - config.user_target.truncate() - - ak_list_router = respx.get( - "https://m.weibo.cn/api/container/getIndex?containerid=1005056279793937" - ) - ak_list_router.mock( - return_value=Response(200, json=get_json("weibo_ak_profile.json")) - ) - ak_list_bad_router = respx.get( - "https://m.weibo.cn/api/container/getIndex?containerid=100505000" - ) - ak_list_bad_router.mock( - return_value=Response(200, json=get_json("weibo_err_profile.json")) - ) - async with app.test_matcher(add_sub_matcher) as ctx: - bot = ctx.create_bot() - event_1 = fake_group_message_event( - message=Message("添加订阅"), - sender=Sender(card="", nickname="test", role="admin"), - to_me=True, - ) - ctx.receive_event(bot, event_1) - ctx.should_pass_rule() - ctx.should_call_send( - event_1, - Message( - BotReply.add_reply_on_platform( - platform_manager=platform_manager, common_platform=common_platform - ) - ), - True, - ) - event_2 = fake_group_message_event( - message=Message("weibo"), sender=fake_admin_user - ) - ctx.receive_event(bot, event_2) - ctx.should_call_send( - event_2, - Message(BotReply.add_reply_on_id(Weibo)), - True, - ) - event_3_err1 = fake_group_message_event( - message=Message( - "https://space.bilbili.com/161775300?from=search&seid=13051774060625135297&spm_id_from=333.337.0.0" - ), - sender=fake_admin_user, - ) - ctx.receive_event(bot, event_3_err1) - ctx.should_call_send( - event_3_err1, BotReply.add_reply_on_target_parse_input_error, True - ) - ctx.should_rejected() - - event_3_err2 = fake_group_message_event( - message=Message("https://weibo.com/arknights"), - sender=fake_admin_user, - ) - ctx.receive_event(bot, event_3_err2) - ctx.should_call_send( - event_3_err2, BotReply.add_reply_on_target_parse_input_error, True - ) - ctx.should_rejected() - - event_3_err3 = fake_group_message_event( - message=Message("https://weibo.com/u/ark6279793937"), - sender=fake_admin_user, - ) - ctx.receive_event(bot, event_3_err3) - ctx.should_call_send( - event_3_err3, BotReply.add_reply_on_target_parse_input_error, True - ) - ctx.should_rejected() - - event_3_ok = fake_group_message_event( - message=Message("http://weibo.com/u/6279793937"), sender=fake_admin_user - ) # 特意写成http测试正则 - ctx.receive_event(bot, event_3_ok) - ctx.should_call_send( - event_3_ok, - BotReply.add_reply_on_target_confirm( - "weibo", "明日方舟Arknights", "6279793937" - ), - True, - ) - ctx.should_call_send( - event_3_ok, - Message(BotReply.add_reply_on_cats(platform_manager, "weibo")), - True, - ) From 7c7989675a0c1756592483456a7ddea32f2f068e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 22 May 2022 15:35:36 +0000 Subject: [PATCH 12/17] auto fix by pre-commit hooks --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eba4dd8..d3f0fb3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 最近更新 -* No changes +- No changes ## v0.5.3 From 11cca571e0ad8dd0c05af527756bc92514f48a97 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 22 May 2022 16:02:49 +0000 Subject: [PATCH 13/17] :memo: Update changelog --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d3f0fb3..6ff566f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,9 @@ ## 最近更新 -- No changes +### 新功能 + +- 增加Parse Target功能 [@felinae98](https://github.com/felinae98) ([#72](https://github.com/felinae98/nonebot-bison/pull/72)) ## v0.5.3 From a32f75688ae1505f514116a0651edd8b430e2825 Mon Sep 17 00:00:00 2001 From: felinae98 <731499577@qq.com> Date: Mon, 23 May 2022 00:16:32 +0800 Subject: [PATCH 14/17] update workflow --- .github/workflows/main.yml | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c6d4e5f..867d1aa 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -72,8 +72,8 @@ jobs: include: - file: ./docker/Dockerfile_with_frontend tags: felinae98/nonebot-bison:main - - file: ./docker/Dockerfile_with_frontend_sentry - tags: felinae98/nonebot-bison:main-sentry + # - file: ./docker/Dockerfile_with_frontend_sentry + # tags: felinae98/nonebot-bison:main-sentry steps: - uses: actions/checkout@v3 @@ -90,19 +90,20 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 - - name: Login to DockerHub - if: github.event_name != 'pull_request' - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - + # - name: Login to DockerHub + # if: github.event_name != 'pull_request' + # uses: docker/login-action@v1 + # with: + # username: ${{ secrets.DOCKER_USERNAME }} + # password: ${{ secrets.DOCKER_PASSWORD }} + # - name: Build and push uses: docker/build-push-action@v2 with: context: . file: ${{ matrix.file }} - push: ${{ github.event_name != 'pull_request' }} + # push: ${{ github.event_name != 'pull_request' }} + push: false tags: ${{ matrix.tags }} cache-from: type=gha cache-to: type=gha,mode=max From f9067454b891c62f3af4fd3df02ad420c9d2ae49 Mon Sep 17 00:00:00 2001 From: felinae98 <731499577@qq.com> Date: Mon, 23 May 2022 11:56:16 +0800 Subject: [PATCH 15/17] Revert "update workflow" This reverts commit a32f75688ae1505f514116a0651edd8b430e2825. --- .github/workflows/main.yml | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 867d1aa..c6d4e5f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -72,8 +72,8 @@ jobs: include: - file: ./docker/Dockerfile_with_frontend tags: felinae98/nonebot-bison:main - # - file: ./docker/Dockerfile_with_frontend_sentry - # tags: felinae98/nonebot-bison:main-sentry + - file: ./docker/Dockerfile_with_frontend_sentry + tags: felinae98/nonebot-bison:main-sentry steps: - uses: actions/checkout@v3 @@ -90,20 +90,19 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 - # - name: Login to DockerHub - # if: github.event_name != 'pull_request' - # uses: docker/login-action@v1 - # with: - # username: ${{ secrets.DOCKER_USERNAME }} - # password: ${{ secrets.DOCKER_PASSWORD }} - # + - name: Login to DockerHub + if: github.event_name != 'pull_request' + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + - name: Build and push uses: docker/build-push-action@v2 with: context: . file: ${{ matrix.file }} - # push: ${{ github.event_name != 'pull_request' }} - push: false + push: ${{ github.event_name != 'pull_request' }} tags: ${{ matrix.tags }} cache-from: type=gha cache-to: type=gha,mode=max From d107aa1cac555b9d26119d1731c7ef486f683d64 Mon Sep 17 00:00:00 2001 From: felinae98 <731499577@qq.com> Date: Mon, 23 May 2022 12:08:32 +0800 Subject: [PATCH 16/17] update ci --- .github/workflows/main.yml | 55 +++++++++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 13 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c6d4e5f..03c5693 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,4 +1,4 @@ -name: CI +name: Test and Build Test Docker on: push: @@ -63,18 +63,10 @@ jobs: uses: codecov/codecov-action@v3 with: env_vars: OS,PYTHON_VERSION - docker: - name: Docker + docker-main: + name: Docker main runs-on: ubuntu-latest needs: [build-frontend, test] - strategy: - matrix: - include: - - file: ./docker/Dockerfile_with_frontend - tags: felinae98/nonebot-bison:main - - file: ./docker/Dockerfile_with_frontend_sentry - tags: felinae98/nonebot-bison:main-sentry - steps: - uses: actions/checkout@v3 @@ -101,8 +93,45 @@ jobs: uses: docker/build-push-action@v2 with: context: . - file: ${{ matrix.file }} + file: ./docker/Dockerfile_with_frontend push: ${{ github.event_name != 'pull_request' }} - tags: ${{ matrix.tags }} + tags: felinae98/nonebot-bison:main + cache-from: type=gha + cache-to: type=gha,mode=max + + docker-main-sentry: + name: Docker main sentry + runs-on: ubuntu-latest + needs: [build-frontend, test] + if: github.event_name != 'pull_request' + steps: + - uses: actions/checkout@v3 + + - name: Download frontend files + uses: actions/download-artifact@v2 + with: + name: frontend + path: ./src/plugins/nonebot_bison/admin_page/dist + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to DockerHub + if: github.event_name != 'pull_request' + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Build and push + uses: docker/build-push-action@v2 + with: + context: . + file: ./docker/Dockerfile_with_frontend_sentry + push: ${{ github.event_name != 'pull_request' }} + tags: felinae98/nonebot-bison:main-sentry cache-from: type=gha cache-to: type=gha,mode=max From 98b8c7d87f3164c5201dce1da6ad3bf023d597c2 Mon Sep 17 00:00:00 2001 From: felinae98 <731499577@qq.com> Date: Mon, 23 May 2022 12:15:15 +0800 Subject: [PATCH 17/17] update readme --- .github/workflows/main.yml | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 03c5693..3725705 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,4 +1,4 @@ -name: Test and Build Test Docker +name: test-build on: push: diff --git a/README.md b/README.md index 40dd42f..473c664 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![pypi](https://badgen.net/pypi/v/nonebot-bison)](https://pypi.org/project/nonebot-bison/) [![license](https://img.shields.io/github/license/felinae98/nonebot-bison)](https://github.com/felinae98/nonebot-bison/blob/main/LICENSE) -[![felinae98](https://circleci.com/gh/felinae98/nonebot-bison.svg?style=shield)](https://circleci.com/gh/felinae98/nonebot-bison) +[![action](https://img.shields.io/github/workflow/status/felinae98/nonebot-bison/test-build)](https://github.com/felinae98/nonebot-bison/actions/workflows/main.yml) [![docker](https://img.shields.io/docker/image-size/felinae98/nonebot-bison)](https://hub.docker.com/r/felinae98/nonebot-bison) [![codecov](https://codecov.io/gh/felinae98/nonebot-bison/branch/main/graph/badge.svg?token=QCFIODJOOA)](https://codecov.io/gh/felinae98/nonebot-bison) [![qq group](https://img.shields.io/badge/QQ%E7%BE%A4-868610060-orange)](https://qm.qq.com/cgi-bin/qm/qr?k=pXYMGB_e8b6so3QTqgeV6lkKDtEeYE4f&jump_from=webapi)