Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/nonebot_plugin_parser/matchers/rule.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import re
from typing import Literal

import msgspec
from msgspec import Struct, DecodeError
from nonebot import logger
from msgspec.json import Decoder
from nonebot.rule import Rule
from nonebot.params import Depends
from nonebot.typing import T_State
Expand All @@ -20,29 +21,29 @@


# 定义 JSON 卡片的数据结构
class MetaDetail(msgspec.Struct):
class MetaDetail(Struct):
qqdocurl: str | None = None


class MetaNews(msgspec.Struct):
class MetaNews(Struct):
jumpUrl: str | None = None


class MetaMusic(msgspec.Struct):
class MetaMusic(Struct):
jumpUrl: str | None = None


class Meta(msgspec.Struct):
class Meta(Struct):
detail_1: MetaDetail | None = None
news: MetaNews | None = None
music: MetaMusic | None = None


class RawData(msgspec.Struct):
class RawData(Struct):
meta: Meta | None = None


raw_decoder = msgspec.json.Decoder(RawData)
raw_decoder = Decoder(RawData)


class SearchResult:
Expand Down Expand Up @@ -81,7 +82,7 @@ def _extract_url(hyper: Hyper) -> str | None:

try:
raw = raw_decoder.decode(raw_str)
except msgspec.DecodeError:
except DecodeError:
logger.exception(f"json 卡片解析失败: {raw_str}")
return None

Expand Down
5 changes: 3 additions & 2 deletions src/nonebot_plugin_parser/parsers/douyin/slides.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from random import choice

from msgspec import Struct, json, field
from msgspec import Struct, field
from msgspec.json import Decoder


class PlayAddr(Struct):
Expand Down Expand Up @@ -59,4 +60,4 @@ class SlidesInfo(Struct):
aweme_details: list[SlidesData] = field(default_factory=list)


decoder = json.Decoder(SlidesInfo)
decoder = Decoder(SlidesInfo)
5 changes: 3 additions & 2 deletions src/nonebot_plugin_parser/parsers/douyin/video.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from random import choice
from typing import Any

from msgspec import Struct, json, field
from msgspec import Struct, field
from msgspec.json import Decoder

from ..base import ParseException

Expand Down Expand Up @@ -95,4 +96,4 @@ def video_data(self) -> VideoData:
raise ParseException("can't find video_(id)/page or note_(id)/page in router data")


decoder = json.Decoder(RouterData)
decoder = Decoder(RouterData)
5 changes: 3 additions & 2 deletions src/nonebot_plugin_parser/parsers/kuaishou/states.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from random import choice

from msgspec import Struct, json, field
from msgspec import Struct, field
from msgspec.json import Decoder


class CdnUrl(Struct):
Expand Down Expand Up @@ -59,4 +60,4 @@ class TusjohData(Struct):
photo: Photo | None = None


decoder = json.Decoder(dict[str, TusjohData])
decoder = Decoder(dict[str, TusjohData])
5 changes: 3 additions & 2 deletions src/nonebot_plugin_parser/parsers/weibo/article.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from msgspec import Struct, json
from msgspec import Struct
from msgspec.json import Decoder


class UserInfo(Struct):
Expand All @@ -20,4 +21,4 @@ class Detail(Struct):
data: Data


decoder = json.Decoder(Detail)
decoder = Decoder(Detail)
5 changes: 3 additions & 2 deletions src/nonebot_plugin_parser/parsers/weibo/common.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from re import sub

from msgspec import Struct, json
from msgspec import Struct
from msgspec.json import Decoder


class LargeInPic(Struct):
Expand Down Expand Up @@ -107,4 +108,4 @@ class WeiboResponse(Struct):
data: WeiboData


decoder = json.Decoder(WeiboResponse)
decoder = Decoder(WeiboResponse)
5 changes: 3 additions & 2 deletions src/nonebot_plugin_parser/parsers/youtube/meta.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from msgspec import Struct, json
from msgspec import Struct
from msgspec.json import Decoder


class Thumbnail(Struct):
Expand Down Expand Up @@ -40,4 +41,4 @@ def description(self) -> str:
return self.metadata.channelMetadataRenderer.description


decoder = json.Decoder(BrowseResponse)
decoder = Decoder(BrowseResponse)
Loading