Skip to content

Commit

Permalink
兼容pydantic<3.0.0,>=1.10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
eya46 committed Dec 3, 2023
1 parent 1f53d90 commit 0b7800d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
8 changes: 3 additions & 5 deletions nonebot_plugin_b23/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
from httpx import AsyncClient
from nonebot import on_command, get_driver
from nonebot import on_command
from nonebot.internal.adapter import Message
from nonebot.params import RawCommand, CommandArg
from nonebot.plugin import PluginMetadata

from .config import Config

config = Config.parse_obj(get_driver().config)
from .config import config, Config

__plugin_meta__ = PluginMetadata(
name="B站热搜",
Expand All @@ -33,7 +31,7 @@

@b23_command.handle()
async def b23_handler(command: str = RawCommand(), arg: Message = CommandArg()):
arg = arg.extract_plain_text()
arg = arg.extract_plain_text().strip()
if arg.isdigit():
try:
arg = int(arg)
Expand Down
11 changes: 10 additions & 1 deletion nonebot_plugin_b23/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Set

from pydantic import BaseModel, Field, Extra
from nonebot import get_driver
from pydantic import BaseModel, Field, Extra, __version__


class Config(BaseModel, extra=Extra.ignore):
Expand All @@ -9,3 +10,11 @@ class Config(BaseModel, extra=Extra.ignore):
b23_block: bool = Field(default=False)
b23_priority: int = Field(default=99)
b23_max_length: int = Field(default=20, gt=0, lt=101)


if __version__[0] == "1":
config = Config.parse_obj(get_driver().config)
elif __version__[0] == "2":
config = Config.model_validate(get_driver().config)
else:
raise Exception(f"不支持的pydantic版本:{__version__}")
8 changes: 6 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
* b23

## 使用

获取B站热搜(默认20条)
> /b23
获取10条B站热搜
> /b23 10

## 作用

获取B站热搜
Expand All @@ -23,10 +23,14 @@

> pip install nonebot-plugin-b23==0.0.9
* nonebot2 2.0.0正式版本👇
* nonebot2 2.0.0+正式版本👇

> pip install nonebot-plugin-b23==0.1.2
* nonebot2 pydantic<3.0.0,>=1.10.0

> pip install nonebot-plugin-b23>=0.2.0
## 配置

| 名称 | 默认值 | 描述 |
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ description = nonebot2 plugin B站热搜
long_description = file: readme.md
long_description_content_type = text/markdown
license = MIT
version = 0.1.2
version = 0.2.0

0 comments on commit 0b7800d

Please sign in to comment.