mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-06 03:46:10 +08:00
调整正则,尝试按照bilibil的parse_target添加weibo的
This commit is contained in:
parent
6c09772980
commit
1763662ed0
@ -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()
|
||||
|
@ -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}
|
||||
|
Loading…
x
Reference in New Issue
Block a user