🧑‍💻 使用 Ruff 包办所有格式化和检查 (#663)

This commit is contained in:
Azide
2024-12-17 10:52:21 +08:00
committed by GitHub
parent af1609730c
commit 08ad5c288c
126 changed files with 875 additions and 933 deletions
@@ -1,13 +1,13 @@
from dataclasses import dataclass
from io import BytesIO
from pathlib import Path
from dataclasses import dataclass
from typing import TYPE_CHECKING, Literal
from nonebot_plugin_saa import Text, Image, MessageSegmentFactory
from nonebot_plugin_saa import Image, MessageSegmentFactory, Text
from nonebot_bison.utils import text_fletten
from nonebot_bison.theme.utils import web_embed_image
from nonebot_bison.theme import Theme, ThemeRenderError, ThemeRenderUnsupportError
from nonebot_bison.theme.utils import web_embed_image
from nonebot_bison.utils import text_fletten
if TYPE_CHECKING:
from nonebot_bison.platform.arknights import ArknightsPost
+4 -3
View File
@@ -1,11 +1,12 @@
from collections.abc import Sequence
from io import BytesIO
from pathlib import Path
from typing import TYPE_CHECKING, Literal
from nonebot_plugin_saa import Text, Image, MessageSegmentFactory
from nonebot_plugin_saa import Image, MessageSegmentFactory, Text
from nonebot_bison.theme import Theme
from nonebot_bison.utils import pic_merge, is_pics_mergable
from nonebot_bison.utils import is_pics_mergable, pic_merge
if TYPE_CHECKING:
from nonebot_bison.post import Post
@@ -50,7 +51,7 @@ class BasicTheme(Theme):
client = await post.platform.ctx.get_client_for_static()
msgs: list[MessageSegmentFactory] = [Text(text)]
pics_group: list[list[str | bytes | Path | BytesIO]] = []
pics_group: list[Sequence[str | bytes | Path | BytesIO]] = []
if post.images:
pics_group.append(post.images)
if rp and rp.images:
+2 -2
View File
@@ -1,9 +1,9 @@
from typing import TYPE_CHECKING, Literal
from nonebot_plugin_saa import Text, Image, MessageSegmentFactory
from nonebot_plugin_saa import Image, MessageSegmentFactory, Text
from nonebot_bison.utils import pic_merge, is_pics_mergable
from nonebot_bison.theme import Theme, ThemeRenderUnsupportError
from nonebot_bison.utils import is_pics_mergable, pic_merge
if TYPE_CHECKING:
from nonebot_bison.post import Post
@@ -1,19 +1,20 @@
from collections.abc import Sequence
from datetime import datetime
from io import BytesIO
from pathlib import Path
from datetime import datetime
from typing import TYPE_CHECKING, Literal
import jinja2
from yarl import URL
from httpx import AsyncClient
from pydantic import BaseModel
import jinja2
from nonebot_plugin_saa import Image, MessageSegmentFactory, Text
from PIL import Image as PILImage
from nonebot_plugin_saa import Text, Image, MessageSegmentFactory
from pydantic import BaseModel
from yarl import URL
from nonebot_bison.compat import model_validator
from nonebot_bison.utils import pic_merge, is_pics_mergable
from nonebot_bison.theme.utils import convert_to_qr, web_embed_image
from nonebot_bison.theme import Theme, ThemeRenderError, ThemeRenderUnsupportError
from nonebot_bison.theme.utils import convert_to_qr, web_embed_image
from nonebot_bison.utils import is_pics_mergable, pic_merge
if TYPE_CHECKING:
from nonebot_bison.post import Post
@@ -122,7 +123,7 @@ class CeobeCanteenTheme(Theme):
@staticmethod
async def merge_pics(
images: list[str | bytes | Path | BytesIO],
images: Sequence[str | bytes | Path | BytesIO],
client: AsyncClient,
) -> list[str | bytes | Path | BytesIO]:
if is_pics_mergable(images):
@@ -224,7 +225,7 @@ class CeobeCanteenTheme(Theme):
text += f"详情: {post.url}"
msgs.append(Text(text))
pics_group: list[list[str | bytes | Path | BytesIO]] = []
pics_group: list[Sequence[str | bytes | Path | BytesIO]] = []
if post.images:
pics_group.append(post.images)
if post.repost and post.repost.images:
+6 -8
View File
@@ -1,12 +1,13 @@
from collections.abc import Sequence
from io import BytesIO
from pathlib import Path
from typing import TYPE_CHECKING, Literal
from nonebot_plugin_saa import Text, Image, MessageSegmentFactory
from nonebot_plugin_saa import Image, MessageSegmentFactory, Text
from nonebot_bison.theme import Theme, ThemeRenderError
from nonebot_bison.post.protocol import HTMLContentSupport
from nonebot_bison.utils import pic_merge, is_pics_mergable
from nonebot_bison.theme import Theme, ThemeRenderError
from nonebot_bison.utils import is_pics_mergable, pic_merge
if TYPE_CHECKING:
from nonebot_bison.post import Post
@@ -31,7 +32,6 @@ class Ht2iTheme(Theme):
raise ThemeRenderError(f"渲染文本失败: {e}")
async def render(self, post: "Post"):
md_text = ""
md_text += f"## {post.title}\n\n" if post.title else ""
@@ -50,9 +50,7 @@ class Ht2iTheme(Theme):
else:
rp_content = await rp.get_content()
md_text += (
"> \n> " + rp_content if len(rp_content) < 500 else f"{rp_content[:500]}..." + " \n" # noqa: E501
) # noqa: E501
md_text += "> \n> " + rp_content if len(rp_content) < 500 else f"{rp_content[:500]}..." + " \n"
md_text += "\n\n"
md_text += f"###### 来源: {post.platform.name} {post.nickname or ''}\n"
@@ -68,7 +66,7 @@ class Ht2iTheme(Theme):
if urls:
msgs.append(Text("\n".join(urls)))
pics_group: list[list[str | bytes | Path | BytesIO]] = []
pics_group: list[Sequence[str | bytes | Path | BytesIO]] = []
if post.images:
pics_group.append(post.images)
if rp and rp.images: