Skip to content

Commit

Permalink
chore
Browse files Browse the repository at this point in the history
  • Loading branch information
lgc2333 committed Sep 5, 2023
1 parent cd7c9eb commit cdb8200
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
7 changes: 3 additions & 4 deletions nonebot_plugin_pjsk/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ConfigModel(BaseModel):
"https://raw.githubusercontent.com/Agnes4m/nonebot_plugin_pjsk/main/",
]

pjsk_emoji_source: str = "Apple"
pjsk_emoji_source: EmojiSource = EmojiSource.Apple
pjsk_help_as_image: bool = True
pjsk_reply: bool = True
pjsk_sticker_format: str = "PNG"
Expand All @@ -41,13 +41,12 @@ def check(url: str) -> str:
raise TypeError("Must be a list of str")
return [check(url) for url in v]

@validator("pjsk_emoji_source")
@validator("pjsk_emoji_source", pre=True)
def check_emoji_source(cls, v): # noqa: N805
try:
getattr(EmojiSource, v)
return getattr(EmojiSource, v)
except AttributeError as e:
raise ValueError("Invalid emoji source") from e
return v


config: ConfigModel = ConfigModel.parse_obj(get_driver().config.dict())
12 changes: 4 additions & 8 deletions nonebot_plugin_pjsk/draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
Canvas,
Color,
EmojiOptions,
EmojiSource,
Font,
Paint,
TextAlign,
Expand All @@ -36,7 +35,7 @@
from .config import config
from .resource import (
CACHE_FOLDER,
FONT_PATHS,
FONT_PATH,
LOADED_STICKER_INFO,
RESOURCE_FOLDER,
StickerInfo,
Expand Down Expand Up @@ -71,11 +70,8 @@ def ensure_font() -> Font:
global FONT
if not FONT:
FONT = Font(
str(FONT_PATHS[0]),
[str(x) for x in FONT_PATHS[1:]],
emoji_options=EmojiOptions(
source=getattr(EmojiSource, config.pjsk_emoji_source),
),
str(FONT_PATH),
emoji_options=EmojiOptions(source=config.pjsk_emoji_source),
)
return FONT

Expand Down Expand Up @@ -329,7 +325,7 @@ async def render_help_image(text: str) -> Image.Image:
width = 1120
font_size = 24
padding = 24
font = ImageFont.truetype(str(FONT_PATHS[-1]), font_size)
font = ImageFont.truetype(str(FONT_PATH), font_size)

warped_lines: List[str] = list(
itertools.chain.from_iterable(
Expand Down
13 changes: 6 additions & 7 deletions nonebot_plugin_pjsk/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
shutil.rmtree(CACHE_FOLDER)
CACHE_FOLDER.mkdir(parents=True)

FONT_PATHS = [
FONT_FOLDER / "YurukaFangTang.ttf",
]
FONT_PATH = FONT_FOLDER / "YurukaFangTang.ttf"

for _folder in (DATA_FOLDER, FONT_FOLDER, RESOURCE_FOLDER):
if not _folder.exists():
Expand Down Expand Up @@ -84,10 +82,11 @@ async def download(font_name: str):

logger.opt(colors=True).info(f"Successfully downloaded font <y>{font_name}</y>")

tasks: List[Coroutine] = [
download(path.name) for path in FONT_PATHS if not path.exists()
]
await asyncio.gather(*tasks)
# tasks: List[Coroutine] = [
# download(path.name) for path in FONT_PATHS if not path.exists()
# ]
# await asyncio.gather(*tasks)
await download(FONT_PATH.name)


async def load_sticker_info():
Expand Down

0 comments on commit cdb8200

Please sign in to comment.