Skip to content

Commit

Permalink
🐛 调整元数据中的Config,为主题配置添加前缀
Browse files Browse the repository at this point in the history
  • Loading branch information
AzideCupric committed Nov 4, 2023
1 parent 95a8f28 commit 72193d3
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 26 deletions.
2 changes: 1 addition & 1 deletion pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 3 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ description = "Bison 官方主题仓库"
authors = [
{name = "AzideCupric", email = "[email protected]"},
]
dependencies = []
dependencies = [
"nonebot-plugin-htmlrender>=0.2.2",
]
requires-python = ">=3.10"
readme = "README.md"
license = {text = "MIT"}
Expand All @@ -25,7 +27,6 @@ requires-python = ">=3.10"
dependencies = [
"nonebot-plugin-htmlrender>=0.2.2"
]
optional-dependencies = []
entry-points = {pdm = {mina = "mina.plugin:ensure_pdm"}}

[tool.mina.packages.basic-theme]
Expand All @@ -41,7 +42,6 @@ authors = [
version = "0.1.0"
requires-python = ">=3.10"
dependencies = []
optional-dependencies = []
entry-points = {pdm = {mina = "mina.plugin:ensure_pdm"}}

[tool.mina.packages.brief-theme]
Expand All @@ -57,7 +57,6 @@ authors = [
version = "0.1.0"
requires-python = ">=3.10"
dependencies = []
optional-dependencies = []
entry-points = {pdm = {mina = "mina.plugin:ensure_pdm"}}

[tool.mina.packages.ceobecanteen-theme]
Expand All @@ -75,7 +74,6 @@ requires-python = ">=3.10"
dependencies = [
"nonebot-plugin-htmlrender>=0.2.2"
]
optional-dependencies = []
entry-points = {pdm = {mina = "mina.plugin:ensure_pdm"}}


Expand All @@ -94,7 +92,6 @@ requires-python = ">=3.10"
dependencies = [
"nonebot-plugin-htmlrender>=0.2.2"
]
optional-dependencies = []
entry-points = {pdm = {mina = "mina.plugin:ensure_pdm"}}


Expand Down
4 changes: 2 additions & 2 deletions theme-template/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
require("nonebot_bison")
from nonebot_bison.theme import theme_manager

from .config import Config
from .parse import NewTheme
from .config import ThemeConfig

__plugin_meta__ = PluginMetadata(
"<theme_name>",
description="<theme_description>",
usage="<theme_usage>",
type="library",
homepage="https://github.com/MountainDash/bison-themes/<theme_name>",
config=ThemeConfig,
config=Config,
supported_adapters=inherit_supported_adapters("nonebot_bison"),
)

Expand Down
4 changes: 2 additions & 2 deletions themes/arknights-theme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
require("nonebot_bison")
from nonebot_bison.theme import theme_manager

from .config import ThemeConfig
from .config import Config
from .parse import ArknightsTheme

__plugin_meta__ = PluginMetadata(
Expand All @@ -13,7 +13,7 @@
usage="pip install nonebot-bison-theme-arknights",
type="library",
homepage="https://github.com/MountainDash/bison-themes/arknights-theme",
config=ThemeConfig,
config=Config,
supported_adapters=inherit_supported_adapters("nonebot_bison"),
)

Expand Down
4 changes: 2 additions & 2 deletions themes/basic-theme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
require("nonebot_bison")
from nonebot_bison.theme import theme_manager

from .config import Config
from .parse import BasicTheme
from .config import ThemeConfig

__plugin_meta__ = PluginMetadata(
"bison-themes-basic",
description="Basic theme for bison",
usage="pip install nonebot-bison-theme-basic",
type="library",
homepage="https://github.com/MountainDash/bison-themes/basic-theme",
config=ThemeConfig,
config=Config,
supported_adapters=inherit_supported_adapters("nonebot_bison"),
)

Expand Down
2 changes: 1 addition & 1 deletion themes/basic-theme/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


class ThemeConfig(BaseModel):
max_cut_length: int = Field(500, description="最大截断长度")
basic_max_cut_length: int = Field(500, description="最大截断长度")


class Config(BaseModel):
Expand Down
4 changes: 2 additions & 2 deletions themes/basic-theme/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ async def render(self, post: "Post") -> list[MessageSegmentFactory]:

text += (
post.content
if len(post.content) < theme_config.max_cut_length
else f"{post.content[:theme_config.max_cut_length]}..."
if len(post.content) < theme_config.basic_max_cut_length
else f"{post.content[:theme_config.basic_max_cut_length]}..."
)

text += f"\n来源: {post.platform.name} {post.nickname or ''}\n"
Expand Down
4 changes: 2 additions & 2 deletions themes/brief-theme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
require("nonebot_bison")
from nonebot_bison.theme import theme_manager

from .config import Config
from .parse import BriefTheme
from .config import ThemeConfig

__plugin_meta__ = PluginMetadata(
"bison-themes-brief",
description="Brief theme for bison",
usage="pip install nonebot-bison-theme-brief",
type="library",
homepage="https://github.com/MountainDash/bison-themes/brief-theme",
config=ThemeConfig,
config=Config,
supported_adapters=inherit_supported_adapters("nonebot_bison"),
)

Expand Down
4 changes: 2 additions & 2 deletions themes/ceobecanteen-theme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
require("nonebot_bison")
from nonebot_bison.theme import theme_manager

from .config import ThemeConfig
from .config import Config
from .parse import CeobeCanteenTheme

__plugin_meta__ = PluginMetadata(
Expand All @@ -13,7 +13,7 @@
usage="pip install nonebot-bison-theme-ceobecanteen",
type="library",
homepage="https://github.com/MountainDash/bison-themes/ceobecanteen-theme",
config=ThemeConfig,
config=Config,
supported_adapters=inherit_supported_adapters("nonebot_bison"),
)

Expand Down
4 changes: 2 additions & 2 deletions themes/ht2i-theme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
require("nonebot_bison")
from nonebot_bison.theme import theme_manager

from .config import Config
from .parse import Ht2iTheme
from .config import ThemeConfig

__plugin_meta__ = PluginMetadata(
"bison-themes-ht2i",
description="ht2i theme for bison",
usage="pip install nonebot-bison-theme-ht2i",
type="library",
homepage="https://github.com/MountainDash/bison-themes/ht2i-theme",
config=ThemeConfig,
config=Config,
supported_adapters=inherit_supported_adapters("nonebot_bison"),
)

Expand Down
2 changes: 1 addition & 1 deletion themes/ht2i-theme/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


class ThemeConfig(BaseModel):
max_cut_length: int | None = Field(None, description="最大截断长度, None为不截断")
ht2i_max_cut_length: int | None = Field(None, description="最大截断长度, None为不截断")

@validator("max_cut_length")
def validate_max_cut_length(cls, v):
Expand Down
6 changes: 3 additions & 3 deletions themes/ht2i-theme/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ async def render(self, post: "Post"):
if post.title:
_text += f"{post.title}\n\n"

if theme_config.max_cut_length:
if theme_config.ht2i_max_cut_length:
_text += (
post.content
if len(post.content) < theme_config.max_cut_length
else f"{post.content[:theme_config.max_cut_length]}..."
if len(post.content) < theme_config.ht2i_max_cut_length
else f"{post.content[:theme_config.ht2i_max_cut_length]}..."
)
else:
_text += post.content if len(post.content) < 500 else f"{post.content[:500]}..."
Expand Down

0 comments on commit 72193d3

Please sign in to comment.