From 48a5ed89e253e69b296927dfa61a7bb7d326115c Mon Sep 17 00:00:00 2001 From: felinae98 <731499577@qq.com> Date: Tue, 2 Nov 2021 20:16:15 +0800 Subject: [PATCH 1/2] add SimplePost --- .../nonebot_hk_reporter/platform/platform.py | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/plugins/nonebot_hk_reporter/platform/platform.py b/src/plugins/nonebot_hk_reporter/platform/platform.py index 3362056..d01bbe4 100644 --- a/src/plugins/nonebot_hk_reporter/platform/platform.py +++ b/src/plugins/nonebot_hk_reporter/platform/platform.py @@ -241,7 +241,7 @@ class Platform(PlatformNameMixin, UserCustomFilterMixin, base=True): ... class NewMessage( - Platform, + Platform, NewMessageProcessMixin, UserCustomFilterMixin, abstract=True @@ -306,6 +306,33 @@ class StatusChange( logger.warning("network connection error: {}, url: {}".format(type(err), err.request.url)) return [] +class SimplePost( + Platform, + MessageProcessMixin, + UserCustomFilterMixin, + StorageMixinProto, + abstract=True + ): + "Fetch a list of messages, dispatch it to different users" + + async def fetch_new_post(self, target: Target, users: list[UserSubInfo]) -> list[tuple[User, list[Post]]]: + try: + new_posts = await self.get_sub_list(target) + if not new_posts: + return [] + else: + for post in new_posts: + logger.info('fetch new post from {} {}: {}'.format( + self.platform_name, + target if self.has_target else '-', + self.get_id(post))) + res = await self.dispatch_user_post(target, new_posts, users) + self.parse_cache = {} + return res + except httpx.RequestError as err: + logger.warning("network connection error: {}, url: {}".format(type(err), err.request.url)) + return [] + class NoTargetGroup( Platform, NoTargetMixin, From d89a9ae106923022d30833de46ab6d945424c9ec Mon Sep 17 00:00:00 2001 From: felinae98 <731499577@qq.com> Date: Wed, 3 Nov 2021 15:14:22 +0800 Subject: [PATCH 2/2] fix stupid bug --- src/plugins/nonebot_hk_reporter/platform/arknights.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/plugins/nonebot_hk_reporter/platform/arknights.py b/src/plugins/nonebot_hk_reporter/platform/arknights.py index 64ce00a..d231d6c 100644 --- a/src/plugins/nonebot_hk_reporter/platform/arknights.py +++ b/src/plugins/nonebot_hk_reporter/platform/arknights.py @@ -53,6 +53,7 @@ class Arknights(NewMessage, NoTargetMixin): pic_data = await render.render(announce_url, viewport=viewport, target='div.main') if pic_data: pics.append(pic_data) + else: text = '图片渲染失败' elif (pic := soup.find('img', class_='banner-image')): pics.append(pic['src'])