mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-05 19:36:43 +08:00
Merge pull request #96 from felinae98/status-change-error
在StatusChange中提供了如果api返回错误不更新status的方法
This commit is contained in:
commit
0c8ff2dfc0
@ -201,7 +201,7 @@ class Bilibililive(StatusChange):
|
||||
info["cover"] = res_dict["data"]["live_room"]["cover"]
|
||||
return info
|
||||
else:
|
||||
return []
|
||||
raise self.ParseTargetException(res.text)
|
||||
|
||||
def compare_status(self, target: Target, old_status, new_status) -> list[RawPost]:
|
||||
if (
|
||||
|
@ -268,6 +268,9 @@ class NewMessage(MessageProcess, abstract=True):
|
||||
class StatusChange(Platform, abstract=True):
|
||||
"Watch a status, and fire a post when status changes"
|
||||
|
||||
class FetchError(RuntimeError):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def get_status(self, target: Target) -> Any:
|
||||
...
|
||||
@ -283,7 +286,11 @@ class StatusChange(Platform, abstract=True):
|
||||
async def fetch_new_post(
|
||||
self, target: Target, users: list[UserSubInfo]
|
||||
) -> list[tuple[User, list[Post]]]:
|
||||
new_status = await self.get_status(target)
|
||||
try:
|
||||
new_status = await self.get_status(target)
|
||||
except self.FetchError as err:
|
||||
logger.warning(f"fetching {self.name}-{target} error: {err}")
|
||||
return []
|
||||
res = []
|
||||
if old_status := self.get_stored_data(target):
|
||||
diff = self.compare_status(target, old_status, new_status)
|
||||
|
Loading…
x
Reference in New Issue
Block a user