mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-07 20:33:01 +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"]
|
info["cover"] = res_dict["data"]["live_room"]["cover"]
|
||||||
return info
|
return info
|
||||||
else:
|
else:
|
||||||
return []
|
raise self.ParseTargetException(res.text)
|
||||||
|
|
||||||
def compare_status(self, target: Target, old_status, new_status) -> list[RawPost]:
|
def compare_status(self, target: Target, old_status, new_status) -> list[RawPost]:
|
||||||
if (
|
if (
|
||||||
|
@ -268,6 +268,9 @@ class NewMessage(MessageProcess, abstract=True):
|
|||||||
class StatusChange(Platform, abstract=True):
|
class StatusChange(Platform, abstract=True):
|
||||||
"Watch a status, and fire a post when status changes"
|
"Watch a status, and fire a post when status changes"
|
||||||
|
|
||||||
|
class FetchError(RuntimeError):
|
||||||
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
async def get_status(self, target: Target) -> Any:
|
async def get_status(self, target: Target) -> Any:
|
||||||
...
|
...
|
||||||
@ -283,7 +286,11 @@ class StatusChange(Platform, abstract=True):
|
|||||||
async def fetch_new_post(
|
async def fetch_new_post(
|
||||||
self, target: Target, users: list[UserSubInfo]
|
self, target: Target, users: list[UserSubInfo]
|
||||||
) -> list[tuple[User, list[Post]]]:
|
) -> list[tuple[User, list[Post]]]:
|
||||||
|
try:
|
||||||
new_status = await self.get_status(target)
|
new_status = await self.get_status(target)
|
||||||
|
except self.FetchError as err:
|
||||||
|
logger.warning(f"fetching {self.name}-{target} error: {err}")
|
||||||
|
return []
|
||||||
res = []
|
res = []
|
||||||
if old_status := self.get_stored_data(target):
|
if old_status := self.get_stored_data(target):
|
||||||
diff = self.compare_status(target, old_status, new_status)
|
diff = self.compare_status(target, old_status, new_status)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user