调整正则,尝试按照bilibil的parse_target添加weibo的

This commit is contained in:
Azide 2022-03-20 23:22:54 +08:00
parent 6c09772980
commit 1763662ed0
2 changed files with 12 additions and 2 deletions

View File

@ -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()

View File

@ -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}