Skip to content

Commit

Permalink
兼容pydantic V2
Browse files Browse the repository at this point in the history
  • Loading branch information
eya46 authored Feb 12, 2024
2 parents 0b7800d + 5198b72 commit 321d104
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 16 deletions.
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
MIT License
Copyright (c) 2018 YOUR NAME
Copyright (c) 2024 eya46
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
Expand Down
13 changes: 4 additions & 9 deletions nonebot_plugin_b23/config.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
from typing import Set

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


class Config(BaseModel, extra=Extra.ignore):
class Config(BaseModel):
b23_default_command: str = Field(default='B站热搜')
b23_commands: Set[str] = Field(default={'b23', })
b23_commands: Set[str] = Field(default_factory=lambda: {'b23', })
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__}")
config = Config(**get_driver().config.dict())
6 changes: 1 addition & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,9 @@

> pip install nonebot-plugin-b23==0.0.9
* 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
> pip install nonebot-plugin-b23>=0.3.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.2.0
version = 0.3.0

0 comments on commit 321d104

Please sign in to comment.