|
1 | 1 | from typing import Any
|
2 |
| -from functools import partial |
3 | 2 |
|
4 | 3 | from httpx import AsyncClient
|
5 | 4 | from bs4 import BeautifulSoup as bs
|
6 | 5 | from pydantic import Field, BaseModel
|
7 | 6 |
|
8 |
| -from ..post import Post |
9 | 7 | from ..types import Target, RawPost, Category
|
10 | 8 | from .platform import NewMessage, StatusChange
|
| 9 | +from ..post import Post, PostHeader, PostPayload |
11 | 10 | from ..utils.scheduler_config import SchedulerConfig
|
12 | 11 |
|
13 | 12 |
|
@@ -106,14 +105,20 @@ def title_escape(text: str) -> str:
|
106 | 105 | title = title_escape(data.title)
|
107 | 106 |
|
108 | 107 | return Post(
|
109 |
| - self, |
110 |
| - content=data.content, |
111 |
| - title=title, |
112 |
| - nickname="明日方舟游戏内公告", |
113 |
| - images=[data.banner_image_url] if data.banner_image_url else None, |
114 |
| - url=data.jump_link or None, |
115 |
| - timestamp=data.updated_at, |
116 |
| - compress=True, |
| 108 | + PostHeader( |
| 109 | + platform_code=self.platform_name, |
| 110 | + http_client=self.client, |
| 111 | + recommend_theme=self.default_theme, |
| 112 | + compress=True, |
| 113 | + ), |
| 114 | + PostPayload( |
| 115 | + content=data.content, |
| 116 | + title=title, |
| 117 | + author="明日方舟游戏内公告", |
| 118 | + images=[data.banner_image_url] if data.banner_image_url else None, |
| 119 | + url=data.jump_link or None, |
| 120 | + timestamp=data.updated_at, |
| 121 | + ), |
117 | 122 | )
|
118 | 123 |
|
119 | 124 |
|
@@ -143,15 +148,30 @@ async def get_status(self, _):
|
143 | 148 |
|
144 | 149 | def compare_status(self, _, old_status, new_status):
|
145 | 150 | res = []
|
146 |
| - ArkUpdatePost = partial(Post, self, "", nickname="明日方舟更新信息") |
| 151 | + |
| 152 | + def make_ark_update_post(title: str): |
| 153 | + return Post( |
| 154 | + PostHeader( |
| 155 | + platform_code=self.platform_name, |
| 156 | + http_client=self.client, |
| 157 | + recommend_theme=self.default_theme, |
| 158 | + compress=True, |
| 159 | + ), |
| 160 | + PostPayload( |
| 161 | + content="", |
| 162 | + title=title, |
| 163 | + author="明日方舟游戏信息", |
| 164 | + ), |
| 165 | + ) |
| 166 | + |
147 | 167 | if old_status.get("preAnnounceType") == 2 and new_status.get("preAnnounceType") == 0:
|
148 |
| - res.append(ArkUpdatePost(title="登录界面维护公告上线(大概是开始维护了)")) |
| 168 | + res.append(make_ark_update_post(title="登录界面维护公告上线(大概是开始维护了)")) |
149 | 169 | elif old_status.get("preAnnounceType") == 0 and new_status.get("preAnnounceType") == 2:
|
150 |
| - res.append(ArkUpdatePost(title="登录界面维护公告下线(大概是开服了,冲!)")) |
| 170 | + res.append(make_ark_update_post(title="登录界面维护公告下线(大概是开服了,冲!)")) |
151 | 171 | if old_status.get("clientVersion") != new_status.get("clientVersion"):
|
152 |
| - res.append(ArkUpdatePost(title="游戏本体更新(大更新)")) |
| 172 | + res.append(make_ark_update_post(title="游戏本体更新(大更新)")) |
153 | 173 | if old_status.get("resVersion") != new_status.get("resVersion"):
|
154 |
| - res.append(ArkUpdatePost(title="游戏资源更新(小更新)")) |
| 174 | + res.append(make_ark_update_post(title="游戏资源更新(小更新)")) |
155 | 175 | return res
|
156 | 176 |
|
157 | 177 | def get_category(self, _):
|
@@ -198,12 +218,18 @@ async def parse(self, raw_post: RawPost) -> Post:
|
198 | 218 | imgs = [x["src"] for x in soup("img")]
|
199 | 219 | text = f'{raw_post["title"]}\n{soup.text.strip()}'
|
200 | 220 | return Post(
|
201 |
| - self, |
202 |
| - text, |
203 |
| - images=imgs, |
204 |
| - url=url, |
205 |
| - nickname="塞壬唱片新闻", |
206 |
| - compress=True, |
| 221 | + PostHeader( |
| 222 | + platform_code=self.platform_name, |
| 223 | + http_client=self.client, |
| 224 | + recommend_theme=self.default_theme, |
| 225 | + compress=True, |
| 226 | + ), |
| 227 | + PostPayload( |
| 228 | + content=text, |
| 229 | + images=imgs, |
| 230 | + url=url, |
| 231 | + author="塞壬唱片新闻", |
| 232 | + ), |
207 | 233 | )
|
208 | 234 |
|
209 | 235 |
|
@@ -238,11 +264,17 @@ def get_category(self, _) -> Category:
|
238 | 264 | async def parse(self, raw_post: RawPost) -> Post:
|
239 | 265 | url = f'https://terra-historicus.hypergryph.com/comic/{raw_post["comicCid"]}/episode/{raw_post["episodeCid"]}'
|
240 | 266 | return Post(
|
241 |
| - self, |
242 |
| - raw_post["subtitle"], |
243 |
| - title=f'{raw_post["title"]} - {raw_post["episodeShortTitle"]}', |
244 |
| - images=[raw_post["coverUrl"]], |
245 |
| - url=url, |
246 |
| - nickname="泰拉记事社漫画", |
247 |
| - compress=True, |
| 267 | + PostHeader( |
| 268 | + platform_code=self.platform_name, |
| 269 | + http_client=self.client, |
| 270 | + recommend_theme=self.default_theme, |
| 271 | + compress=True, |
| 272 | + ), |
| 273 | + PostPayload( |
| 274 | + content=raw_post["subtitle"], |
| 275 | + title=f'{raw_post["title"]} - {raw_post["episodeShortTitle"]}', |
| 276 | + images=[raw_post["coverUrl"]], |
| 277 | + url=url, |
| 278 | + author="泰拉记事社漫画", |
| 279 | + ), |
248 | 280 | )
|
0 commit comments