mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-07 20:33:01 +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:
|
async def parse_target(self, target_text: str) -> Target:
|
||||||
if re.match(r"\d+", target_text):
|
if re.match(r"\d+", target_text):
|
||||||
return Target(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))
|
return Target(match.group(1))
|
||||||
else:
|
else:
|
||||||
raise Platform.ParseTargetException()
|
raise Platform.ParseTargetException()
|
||||||
|
@ -9,7 +9,7 @@ from nonebot.log import logger
|
|||||||
|
|
||||||
from ..post import Post
|
from ..post import Post
|
||||||
from ..types import *
|
from ..types import *
|
||||||
from .platform import NewMessage
|
from .platform import NewMessage, Platform
|
||||||
|
|
||||||
|
|
||||||
class Weibo(NewMessage):
|
class Weibo(NewMessage):
|
||||||
@ -28,6 +28,7 @@ class Weibo(NewMessage):
|
|||||||
schedule_type = "interval"
|
schedule_type = "interval"
|
||||||
schedule_kw = {"seconds": 3}
|
schedule_kw = {"seconds": 3}
|
||||||
has_target = True
|
has_target = True
|
||||||
|
parse_target_promot = "请输入用户主页(包含数字UID)的链接"
|
||||||
|
|
||||||
async def get_target_name(self, target: Target) -> Optional[str]:
|
async def get_target_name(self, target: Target) -> Optional[str]:
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
@ -41,6 +42,15 @@ class Weibo(NewMessage):
|
|||||||
else:
|
else:
|
||||||
return None
|
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 def get_sub_list(self, target: Target) -> list[RawPost]:
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
params = {"containerid": "107603" + target}
|
params = {"containerid": "107603" + target}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user