Skip to content

Commit

Permalink
0.2.10
Browse files Browse the repository at this point in the history
  • Loading branch information
lgc2333 committed Nov 6, 2023
1 parent 73db11a commit 1e751f0
Show file tree
Hide file tree
Showing 9 changed files with 557 additions and 425 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ _✨ Project Sekai 表情包制作 ✨_
## 💬 前言

- 如遇字体大小不协调问题,请更新插件到最新版本,并且删除 `data/pjsk/fonts` 文件夹下的所有文件
- 如果遇到资源文件下载失败的情况,请参考 [这个 issue](https://github.com/Agnes4m/nonebot_plugin_pjsk/issues/15)
- 如遇找不到包无法安装的情况,请先确认你使用的 Python 版本是否 `>=3.9``<=3.11`
- ~~由于本人没玩过啤酒烧烤,~~ 可能出现一些小问题,可以提 issue 或者 [加群](https://jq.qq.com/?_wv=1027&k=l82tMuPG)反馈 ~~或者单纯进来玩~~
- 本项目仅供学习使用,请勿用于商业用途,喜欢该项目可以 Star 或者提供 PR,如果构成侵权将在 24 小时内删除

<!-- - 如果遇到资源文件下载失败的情况,请参考 [这个 issue](https://github.com/Agnes4m/nonebot_plugin_pjsk/issues/15) -->

## 📖 介绍

### Wonderhoy!
Expand Down Expand Up @@ -187,6 +189,12 @@ Telegram:[@lgc2333](https://t.me/lgc2333)

## 📝 更新日志

### 0.2.10

- 修复指定保存格式无效的 Bug
- 添加指令参数 `--auto-adjust``-A`
- 其他小修改

### 0.2.9

- 指令参数增加与变更:
Expand Down
Binary file modified fonts/YurukaFangTang.ttf
Binary file not shown.
2 changes: 1 addition & 1 deletion nonebot_plugin_pjsk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from . import __main__ as __main__ # noqa: E402
from .config import ConfigModel # noqa: E402

__version__ = "0.2.9"
__version__ = "0.2.10"
__plugin_meta__ = PluginMetadata(
name="Sekai Stickers",
description="基于 NoneBot2 的 Project Sekai 表情包制作插件",
Expand Down
16 changes: 12 additions & 4 deletions nonebot_plugin_pjsk/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@
"--format",
help=f"图片保存的格式,默认为 {config.pjsk_sticker_format}",
)
cmd_generate_parser.add_argument(
"-A",
"--auto-adjust",
action="store_true",
help="启用字号自动调整",
)

cmd_generate = on_shell_command(
"pjsk",
Expand Down Expand Up @@ -118,12 +124,15 @@ async def _(matcher: Matcher, args: Namespace = ShellCommandArgs()):
if not any(vars(args).values()): # 没有任何参数
matcher.skip() # 跳过该 handler 进入交互模式

texts: List[str] = args.text
if not all(isinstance(x, str) for x in texts):
await matcher.finish("只接受字符串参数")

sticker_id: Optional[str] = args.id
selected_sticker = select_or_get_random(sticker_id)
if not selected_sticker:
await matcher.finish("没有找到对应 ID 的表情")

texts: List[str] = args.text
default_text = selected_sticker.default_text
try:
image = await draw_sticker(
Expand All @@ -141,8 +150,7 @@ async def _(matcher: Matcher, args: Namespace = ShellCommandArgs()):
stroke_width=resolve_value(args.stroke_width, DEFAULT_STROKE_WIDTH),
stroke_color=args.stroke_color or DEFAULT_STROKE_COLOR,
line_spacing=resolve_value(args.line_spacing, DEFAULT_LINE_SPACING, float),
# font_weight=resolve_value(args.weight, DEFAULT_FONT_WEIGHT),
auto_adjust=args.size is None,
auto_adjust=args.auto_adjust or (args.size is None),
)
except Exception as e:
await matcher.finish(format_draw_error(e))
Expand Down Expand Up @@ -249,5 +257,5 @@ async def _(
except Exception as e:
await matcher.finish(format_draw_error(e))

image_bytes = i2b(image, config.pjsk_sticker_format)
image_bytes = i2b(image)
await MessageFactory([Image(image_bytes)]).finish(reply=config.pjsk_reply)
44 changes: 22 additions & 22 deletions nonebot_plugin_pjsk/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,44 @@

from imagetext_py import EmojiSource
from nonebot import get_driver
from pydantic import BaseModel, validator
from pydantic import BaseModel, Field, HttpUrl, validator


class ConfigModel(BaseModel):
command_start: Set[str]

pjsk_req_retry: int = 2
pjsk_req_proxy: Optional[str] = None
pjsk_assets_prefix: List[str] = [
"https://ghproxy.com/https://raw.githubusercontent.com/TheOriginalAyaka/sekai-stickers/main/",
"https://raw.gitmirror.com/TheOriginalAyaka/sekai-stickers/main/",
"https://raw.githubusercontent.com/TheOriginalAyaka/sekai-stickers/main/",
]
pjsk_repo_prefix: List[str] = [
"https://ghproxy.com/https://raw.githubusercontent.com/Agnes4m/nonebot_plugin_pjsk/main/",
"https://raw.gitmirror.com/Agnes4m/nonebot_plugin_pjsk/main/",
"https://raw.githubusercontent.com/Agnes4m/nonebot_plugin_pjsk/main/",
]
pjsk_req_timeout: int = 10
pjsk_assets_prefix: List[HttpUrl] = Field(
[
"https://ghproxy.com/https://raw.githubusercontent.com/TheOriginalAyaka/sekai-stickers/main/",
"https://raw.gitmirror.com/TheOriginalAyaka/sekai-stickers/main/",
"https://raw.githubusercontent.com/TheOriginalAyaka/sekai-stickers/main/",
],
)
pjsk_repo_prefix: List[HttpUrl] = Field(
[
"https://ghproxy.com/https://raw.githubusercontent.com/Agnes4m/nonebot_plugin_pjsk/main/",
"https://raw.gitmirror.com/Agnes4m/nonebot_plugin_pjsk/main/",
"https://raw.githubusercontent.com/Agnes4m/nonebot_plugin_pjsk/main/",
],
)

pjsk_emoji_source: str = "Apple"
pjsk_help_as_image: bool = True
pjsk_reply: bool = True
pjsk_sticker_format: str = "PNG"

@validator("pjsk_assets_prefix", "pjsk_repo_prefix", pre=True)
def check_url_list(cls, v): # noqa: N805
def check(url: str) -> str:
if not url.startswith(("http://", "https://")):
raise ValueError("URL must start with http:// or https://")
if not url.endswith("/"):
url = f"{url}/"
return url

def str_to_list(cls, v): # noqa: N805
if isinstance(v, str):
v = [v]
if not isinstance(v, list):
raise TypeError("Must be a list of str")
return [check(url) for url in v]
return v

@validator("pjsk_assets_prefix", "pjsk_repo_prefix")
def append_slash(cls, v): # noqa: N805
return [v if v.endswith("/") else f"{v}/" for v in v]

@validator("pjsk_emoji_source", pre=True)
def check_emoji_source(cls, v): # noqa: N805
Expand Down
Loading

0 comments on commit 1e751f0

Please sign in to comment.